Protractor Interview Questions | Software Testing Material [Updated 2020]

This post on Protractor Interview Questions is designed to prepare candidates for common questions they are likely to encounter when applying for a Protractor Automation Jobs. It covers both basic and advanced Protractor Interview Questions. Before going ahead, let’s see some unavoidable Interview Questions such as What Are The Reasons For Choosing Software Testing As Your Career and Explain Your Test Automation Framework.

Related Posts:

Protractor Interview Questions

1. What is Protractor?

Protractor is an end-to-end test framework for Angular and Angular JS applications. Protractor runs tests against your application running in a real browser, interacting with it as a user would. Protractor is a node.js port of the webdriver.io, which is the JavaScript implementation of Selenium framework.
Protractor is a Node.js program that supports test frameworks like Jasmine, Mocha, and Cucumber.

2. What are the prerequisites required to run Protractor?

To run Protractor, we need to have Selenium WebDriver and Node.js installed. We can download Protractor package using npm.

Learn how to install Selenium (latest version)

3. How Protractor, Selenium Server, and Selenium WebDriver work together?

Protractor is an end-to-end test framework for AngularJS applications. Protractor is a Node.js program that supports the Jasmine and Mocha test frameworks.
Selenium is a browser automation framework. Selenium includes the Selenium Server, the WebDriver APIs, and the WebDriver browser drivers.
Protractor works in conjunction with Selenium to provide an automated test infrastructure that can simulate a user’s interaction with an Angular application running in a browser or mobile device.

4. Why you choose Protractor when testing an application built on Angular or Angular JS and not Selenium?

There is no rule that you must use Protractor when the UI is built with Angular or AngularJS. It depends upon your requirement and team knowledge. Both these tools (Protractor & Selenium) helps us in flawless browser automation.
You can just use plain Selenium for testing Angular applications. Protractor just makes it easier to test Angular application. Protractor is a framework for testing Angular applications.
It has Automatic Waiting for elements and you can access specific Angular elements by.model and by.binding. Also it implements the Page Objects in the framework making tests more maintainable if used correctly.
Some of the points to consider when taking a decision on whether to go with Protractor or not. These points are some of the features of Protractor that make it worthy for testing AngularJS applications.
1. Protractor is a wrapper around WebDriverJS and supports Behavior Driven Development Frameworks such as Jasmine, Cucumber, Mocha etc.,
2. Protractor works in conjunction with Selenium. It offers some other new locator strategies that automate the testing of AngularJS applications.
3. Protractor makes use of Selenium Grid to run Multiple browsers at once.
4. Protractor handles the $http or $timeout synchronisation issues arising out of Angular/Angular JS very well.
5. Angular/Angular JS code is written in JavaScript/TypeScript, and Protractor supports both these languages.

5. Can Protractor be used for testing Non-Angular JS Applications?

Yes. Protractor can be used for testing Non-Angular JS or Non-Angular Apps.

6. What are the test frameworks supported by Protractor?

Protractor supports two behavior driven development (BDD) test frameworks such as Jasmine & Mocha.

7. What is Jasmine?

Jasmine is an open source testing framework for JavaScript. It aims to run on any JavaScript-enabled platform. It doesn’t require a DOM and it has a clean, obvious syntax so that we can easily write tests.

8. What is Mocha?

Mocha is a JavaScript test framework for Node.js programs, featuring browser support, asynchronous testing, test coverage reports, and use of any assertion library.

9. What is Typescript?

TypeScript is a super set of JavaScript compiled to JavaScript. TypeScript is a strongly typed, object oriented, compiled language developed and maintained by Microsoft. TypeScript may be used to develop JavaScript applications for both client-side and server-side (Node.js) execution.

10. What is a conf file in Protractor?

The configuration file tells Protractor how to set up the Selenium Server, which tests to run, how to set up the browsers, and which test framework to use. The configuration file can also include one or more global settings. The config file provides explanations for all of the Protractor configuration options. Default settings include the standalone Selenium Server, the Chrome browser, and the Jasmine test framework.

11. What is a spec file in Protractor?

Spec file is the one where we write actual test code. It contains the logic and locators to interact with an application.

12. How to exclude a spec file in Protractor?

You can exclude the spec’s by adding them in the exclude tag in your conf.js file. You can also add patterns to exclude many test scripts with similar names.
Sometimes we may face a situation of running only few tests out of all. In this case, we use exclude tag in our conf.js file to run only few tests. Say we want to exclude test name “myTest.js”
exclude: [myTest.js]

13. What is the use of directConnect in Protractor?

Protractor can test directly against Chrome and Firefox without using a Selenium Server. To use this, in your config file set directConnect: true.
directConnect: true – Your test script communicates directly Chrome Driver or Firefox Driver, bypassing any Selenium Server. If this is true, settings for seleniumAddress and seleniumServerJar will be ignored. If you attempt to use a browser other than Chrome or Firefox an error will be thrown.
The advantage of directly connecting to browser drivers is that your test scripts may start up and run faster.

14. What are the locators in Protractor?

Protractor supports all the element location strategies given by Selenium and it also has unique set of locators particularly to identify elements based on AngularJS attributes.

Selenium locators:

by.className
by.css
by.id
by.linkText
by.name
by.partialLinkText
by.tagName
by.xpath

Angular Specific Locators

by.binding
by.exactBinding
by.model
by.repeater
by.exactRepeater
by.options

Other element locator’s introduced in Protractor:

by.buttonText
by.paritalButtonText
by.cssContainingText
by.deepCss

15. How to add custom locator for Protractor?

By using addLocator method.

Refer this example

16. How do you check the status of a webdriver manager and how do you update webdriver manager?

To check the status of webdriver manager, run the following in your command prompt

webdriver-manager status

To update webdriver manager, run the following code in your command prompt

webdriver-manager update

17. What is ElementFinder?

The ElementFinder simply represents a single element of an ElementArrayFinder (and is more like a convenience object). As a result, anything that can be done with an ElementFinder, can also be done using an ElementArrayFinder.
The ElementFinder can be treated as a WebElement for most purposes, in particular, you may perform actions (i.e. click, getText) on them as you would a WebElement. Once an action is performed on an ElementFinder, the latest result from the chain can be accessed using the then method. Unlike a WebElement, an ElementFinder will wait for angular to settle before performing finds or actions.
ElementFinder can be used to build a chain of locators that is used to find an element. An ElementFinder does not actually attempt to find the element until an action is called, which means they can be set up in helper files before the page is available.
element(by.locator(“locator value”))

18. What is an ElementArrayFinder?

ElementArrayFinder is used for operations on an array of elements. The ElementArrayFinder is used to set up a chain of conditions that identify an array of elements. In particular, you can call all(locator) and filter(filterFn) to return a new ElementArrayFinder modified by the conditions, and you can call get(index) to return a single ElementFinder at position ‘index’.
Similar to jquery, ElementArrayFinder will search all branches of the DOM to find the elements that satisfy the conditions (i.e. all, filter, get). However, an ElementArrayFinder will not actually retrieve the elements until an action is called, which means it can be set up in helper files (i.e. page objects) before the page is available, and reused as the page changes.

19. What is browser.refresh in Protractor?

browser.refresh makes a full reload of the current page and loads mock modules before Angular. Assumes that the page being loaded uses Angular. If you need to access a page which does not have Angular on load, use the wrapped webdriver directly.

20. What is the difference between “GET” and “NAVIGATE in Protractor?

Get:
Get method is used to navigate to the given destination.
browser.get(“https://www.softwaretestingmaterial.com”);

Navigate:
Navigate method is used to navigate to the given destination
browser.navigate()

if we want to load a previous page or next page in a browser we can use back and forward.

browser.navigate().back();
browser.navigate().forward();

21. How to find all the links on a webpage using Protractor?

We can find all the links on a webpage using tagName ‘a’. Usually all the links are formed with an anchor tag ‘a’ and all the links will have ‘href’ attribute with URL value.

22. How do you verify tooltip text using Protractor?

We can verify tooltip text using protractor by fetching the value of ‘title’ attribute.

23. What are the mouse actions that can be performed using Protractor?

1. click()
2. doubleClick()
3. contextClick()
4. mouseUp()
5. mouseDown(element)
6. mouseMove(element)
7. mouseMove(xOffset, yOffset)
8.dragAndDrop(element1, element2)

24. Why getText() method returns Object instead of String in Protractor?

When using Java, getText() method returns the corresponding text from the element. However in Protractor, getText() method returns Object something like [objectObject] In Protractor, the getText() method returns a Promise. We need to resolve this in order to get the text.

Syntax:

25. How to get text from a textbox in Protractor?

By using getAttribute method by passing argument as value. getAttribute() method returns a promise which contains String

Syntax:

26. How do you verify whether an element exists on a webpage using Protractor?

To determine whether an element exists on a webpage with isPresent function

// Element exists
expect(element(by.binding(‘person.name’)).isPresent()).toBe(true);

// Element not present
expect(element(by.binding(‘notPresent’)).isPresent()).toBe(false);

27. What are the methods present in Alerts Class?

Methods present in Alerts Class are
1. accept()
2. dismiss()
3. getText()
4. sendKeys()

28. How to set value to prompt Alert in Protractor?

By using sendKeys() method of Alerts class, we set value to the prompt Alert in Protractor.

29. How to accept Alert in Protractor?

By using accept() method of Alerts class, we accept Alerts in Protractor.

Note: We have to switch the control to the alert using switchTo().alert() before accepting the alert.

30. How to cancel Alert in Protractor?

By using dismiss() method of Alerts class, we cancel or close alerts in Protractor.

Note: We have to switch the control to the alert using switchTo().alert() before cancel the alert.

31. How do you stop Page Loading in Protractor when an element is loaded?

By using Key.ESC to body element in Protractor.

32. How to verify whether an element is displayed on a webpage or not?

To verify whether an element is displayed on a webpage or not, we use isDisplayed() method in Protractor. isDisplayed() method returns a Boolean value based on the state of the element in a webpage. It returns true if the element is displayed and false if the element is not displayed.

33. How to verify whether an element is enabled or not?

To verify whether an element is enabled or not, we use isEnabled() method in Protractor. isEnabled() method returns a Boolean value based on the state of the element. It returns true if the element is enabled and false if the element is not enabled.

34. How to verify whether a dropdown is selected or not in angular applications?

To verify whether a dropdown list is selected or not in angular applications using Protractor, we use isSelected() method. isSelected() method returns Boolean value. It returns true if the element is selected and false if the element is not selected.

35. How do you find Angular on your page?

Open chrome devtools or firefox and find if ‘angular’ is defined. For AngularJS apps, the ‘angular’ variable is expected to be available in the global context.

Note: Check your version of Angular is upgraded – Protractor supports Angular and AngularJS 1.0.6/1.1.4 and higher.

36. What are the browsers supported by Protractor?

Protractor supports the two latest major versions of Chrome, Firefox, Safari, and IE.

Check out full list of supported browsers here.

I am going to conclude this Protractor Interview Questions. Here I have hand-picked a few posts which will help you to learn more interview related stuff:

If you have any more question, feel free to ask via comments. If you find this post useful, do share it with your friends on Social Networking.

Get our latest blog posts delivered to your inbox

Subscribe and get popular blog posts about software testing industry.

Rajkumar

Leave a Comment

Share via
Copy link
Powered by Social Snap