Protractor Interview Questions

  1. What do you need to run Protractor?
  2. Can you use Protractor for testing Non-Angular JS applications? How?
  3. Which test frameworks does Protractor support?
  4. What is a spec file in Protractor?
  5. What does directConnect do in Protractor?
  6. How do you add a custom locator for Protractor?
  7. Which mouse actions can be performed using Protractor?
  8. Can you verify whether an element exists on a webpage using Protractor? If yes, then how?
  9. How to accept an alert in Protractor?
  10. How to cancel an alert in Protractor?
  11. How can you verify whether an element is enabled or not?
  12. Can you verify whether an element is displayed on a webpage or not? If yes, then how?
  13. Name the browsers supported by Protractor.
  14. How to handle installation in Protractor?
  15. How can you verify tooltip text using Protractor?
  16. Does Protractor handle Windows based popup?
  17. How to find all the links on the webpage?
  18. What is WebElement in Protractor?
  19. What is a Time-Out test in Protractor?
  20. How to focus on an input element On- Page using Protractor?
  21. How to extract the CSS attribute of an element in Protractor?
  22. How to switch between frames using Protractor?
  23. State the difference between “GET” and “NAVIGATE” to open a webpage in Protractor.
  24. How to set the value to prompt alert in Protractor?
  25. Can we set global variables in Protractor?
  26. What is maxInstances in Protractor?
  27. What is Typescript?
  28. How to set the geckodriver path in Protractor?
  29. What is ElementFinder?
  30. What is an XPath?
  31. How can we run the headless browser mode in Protractor?
  32. Explain about group index in XPath.
  33. What are the Selenium specific locators in Protractor?
  34. What is ElementArrayFinder?
  35. Can we perform drag and drop in Protractor? If yes, write the code for it.
  36. What is the use of the webdriver-manager update command?
  37. What are some possible timeouts that can occur in Protractor?
  38. How to perform reporting in Protractor?
  39. How can Protractor work in conjunction with Selenium Server and Selenium WebDriver?
  40. What does a conf file do in Protractor?
  41. Write code to check if an element by id exists on a web page in Protractor.
  42. What is the use of browser.refresh in Protractor?
  43. How can we handle alerts and what are the methods of Alert Class in Protractor?
  44. Can you verify if a dropdown is selected or not in angular applications?
  45. Write code to overwrite the current input value of an editable field on the page.
  46. What is the default time for a Jasmine spec to fail? Can we change that time?
  47. Can we run multiple specs in Protractor?
  48. According to you, what would be the order of browsers in terms of faster implementation in Protractor?
  49. Explain the difference between browser.close() and browser.quit() commands?
  50. How can we execute a spec file in both chrome and firefox?
 
1. What do you need to run Protractor?

Ans: To run Protractor, you will require a compatible version of Node.js installed and Selenium WebDriver. You will download the Protractor package using npm that comes with Node.js.

You will also need the test or spec file, and the configuration file to run Protractor. While the configuration file is simple, the spec file (test) is written using the chosen test framework’s syntax like Jasmine or Mocha in addition to Protractor API.

2. Can you use Protractor for testing Non-Angular JS applications? How?

Ans: Yes,Protractor can be used for testing non-Angular JS applications. Although Protractor is an end-to-end test framework for Angular JS applications, but it can also be used for testing non-Angular JS applications. 

  • Protractor requires Jasmine, Javascript, Selenium and Node.js server. 
  • Using Protractor for non-Angular JS applications should be followed by:
  • Using browser.driver in place of driver
  • Using browser.driver.ignoreSynchronization=true
3. Which test frameworks does Protractor support?

Ans: Protractor is a Node.js program that supports two test frameworks: Jasmine and Mocha. These are behaviour driven development (BDD) test frameworks and are based on JavaScript and Node.js. They provide the syntax, scaffolding and reporting tools that are used to write & manage tests.

4. What is a spec file in Protractor?

Ans: A spec file is where we write actual test code. This file contains the logic and locators that assist in interacting with an application. It contains the specs or automated test cases that are known as Test Scripts.

5. What does directConnect do in Protractor?

Ans: If you set directConnect: true in your config file, your test script will communicate directly with Chrome Driver or Firefox Driver. Settings for seleniumAddress and seleniumServerJar will be ignored if this is true. 

The use of directly connecting to browser drivers is that your test scripts may begin to run faster.

6. How do you add a custom locator for Protractor?

Ans: For Protractor, addLocator method can be used with element(by.locatorName(args)) to add your own custom locator in the framework.

7. Which mouse actions can be performed using Protractor?

Ans: Mouse actions that can be performed using Protractor are:

  • click(element)
  • doubleClick(element)
  • contextClick(element)
  • mouseDown(element)
  • mouseUp(element)
  • mouseMove(element)
  • mouseMove(element, long xOffset, long yOffset)
  • dragAndDrop()
8. Can you verify whether an element exists on a webpage using Protractor? If yes, then how?

Ans: Yes, we can verify whether an element exists on a webpage using a Protractor. It can be done by using isPresent() function.

9. How to accept an alert in Protractor?

Ans: To accept an alert in Protractor, accept() method of Alerts class is used. Before accepting the alert, switch the control to the alert by using switchTo().alert().

10. How to cancel an alert in Protractor?

Ans: To cancel an alert in Protractor, dismiss() method of Alerts class is used. Before cancelling the alert, switch the control to the alert by using switchTo().alert(). It does not click on the cancel button, but on the ‘X’ icon on the alert.

11. How can you verify whether an element is enabled or not?

Ans: To verify whether an element is enabled or not, isEnabled() method is used in Protractor. This method returns a Boolean value. If the element is enabled, then it returns true. If the element is not enabled, then it returns false.

12. Can you verify whether an element is displayed on a webpage or not? If yes, then how?

Ans: Verifying whether an element is displayed on a webpage or not can be done using isDisplayed() in Protractor. This method returns a Boolean value as per the state of the element. It returns true if the element is displayed and returns false if the element is not displayed.

13. Name the browsers supported by Protractor.

Ans: Protractor supports the two latest and major versions of Chrome, Firefox, Safari and IE. Protractor uses WebDriver to drive browsers and the issues related to WebDriver implementations. 

14. How to handle installation in Protractor?

Ans: The node will install the specified version in our system when we use the package.json file as installation files and specify a version in package json.

15. How can you verify tooltip text using Protractor?

Ans: You can verify tooltip text using Protractor, we need to fetch the value of ‘title’ attribute. 

16. Does Protractor handle Windows based popup?

Ans: No. Windows based popup cannot be handled using Protractor as it is a web automation testing tool that supports only web application testing.

17. How to find all the links on the webpage?

Ans: Anchor tag ‘a’ is used to form each link, and all the links have a href attribute with URL value. We can locate elements of tagName ‘a’ to find all the links on the webpage. 

18. What is WebElement in Protractor?

Ans: Protractor converts ElementFinder into WebElement when we perform any action on ElementFinder. This method is called by every method before it operates on the webpage object. 

19. What is a Time-Out test in Protractor?

Ans: Time-out test is the time allotted for performing unit testing. Protractor discontinues further testing if the unit test fails to meet the specified time limit and marks it as a failure. 

20. How to focus on an input element On- Page using Protractor?

Ans: You can click the mouse on the element to focus on it.

21. How to extract the CSS attribute of an element in Protractor?

Ans: To extract the CSS attribute of an element in Protractor, grtCSSValue can be used.

22. How to switch between frames using Protractor?

Ans: To have your webdriver script switch between different frames, you can use the following code:

browser.switchTo().frame(element(by.xpath("//iframe[@src='demo.html']")).getWebElement())
23. State the difference between “GET” and “NAVIGATE” to open a webpage in Protractor.

Ans: Get method loads a page or gets the page source or gets text. 

On the other hand, navigate method allows functions like refresh, back and forward. 

24. How to set the value to prompt alert in Protractor?

Ans: To set the value to prompt alert in Protractor, sendKeys() method of Alerts class is used.

25. Can we set global variables in Protractor?

Ans: It is possible to set global variables using params present in the conf file that can be accessed in the specs using

browser.params.glob.

26. What is maxInstances in Protractor?

Ans: MaxInstances in Protractor is the number of browser instances that can run in parallel for the set of capabilities.

27. What is Typescript?

Ans: Typescript is a programming language and the superset of Javascript. It provides syntaxes like Java/Python and provides the Javascript function.

28. How to set the geckodriver path in Protractor?

Ans: geckoDriver location finds the geckodriver.exe file. This gets passed to the Selenium jar as the system property.webdriver.gecko.driver. 

29. What is ElementFinder?

Ans: ElementFinder refers to the elements present on the webpage. It can be used to build a chain of locators to find an element.

30. What is an XPath?

Ans: XPath is one of those locators that are supported by Protractor and is a query language for selecting nodes from XML documents. 

31. How can we run the headless browser mode in Protractor?

Ans: A headless browser mode means running web applications without a graphical user interface. The applications will get executed through commands via a command-line interface. In the headless browser mode, the Protractor executes the tests in the background. To start a browser in headless mode, we need to specify the –headless flag for the browser that you want in the Protractor config file.

32. Explain about group index in XPath.

Ans: When we search for an element with the XPath index, we might get more than one element that is under different parents. The group index places all the resulting element matches into a list and gives indexes for them. The group index numbers start with 1. This way, there won’t be any duplicates in matches.

33. What are the Selenium specific locators in Protractor?

Ans: Here are the Selenium specific locators available in Protractor.

  • By Class Name
  • By CSS
  • By Id
  • By Link Text
  • By Name
  • By Partial Link Text
  • By Tag Name
  • By XPath
34. What is ElementArrayFinder?

Ans: The ElementArrayFinder is used to identify an array of elements by setting up a chain of conditions. It searches for the elements all through the branches of DOM that satisfy the set conditions (i.e., all, filter, get). We can perform actions on an array of elements. You can retrieve all elements or apply some filters to return specific elements. When you perform an action on the ElementArrayFinder, it will apply to each element of the ElementArrayFinder, and the results will be returned as an array of the results.

35. Can we perform drag and drop in Protractor? If yes, write the code for it.

Ans: Yes, we can implement drag and drop in Protractor using actions(). Here is the code for it.

browser.actions().dragAndDrop(Element,Target).mouseUp().perform();

Element – The element that you want to drag
Target – Where you want to drop the element to

36. What is the use of the webdriver-manager update command?

Ans: The webdriver-manager update command is used to install the server along with the browser dependencies. It also downloads the latest binaries of Protractor to connect to browsers using the Selenium server.

37. What are some possible timeouts that can occur in Protractor?

Ans: Here are some of the timeouts that can occur in Protractor.

  • Waiting for a page to load – the default timeout is 10 seconds.
  • Waiting for Angular to finish asynchronous tasks – the default timeout is 11 seconds.
  • Waiting for Angular on page load – the default timeout is 10 seconds.
  • Asynchronous script timeout – the default timeout is 11 seconds.
  • Spec timeout – the default timeout is 30 seconds.
38. How to perform reporting in Protractor?

Ans: The protractor does not come with reporting features by default. But we can implement reporting through the reporter of the framework used. For instance, if you are using Jasmine 2.0 with Protractor, you can use Allure for reporting. If you are using Mocha, you can use Mochawesome.

39. How can Protractor work in conjunction with Selenium Server and Selenium WebDriver?

Ans: Protractor is based on Node.js to perform end-to-end tests on AngularJS applications. It supports Jasmine and Mocha test frameworks. Selenium is an automated testing framework to test web applications on various platforms and browsers. Protractor works in conjunction with Selenium to simulate a user’s interaction with an Angular application running either on mobile or on the browser.

40. What does a conf file do in Protractor?

Ans: The conf file is a javascript configuration file that specifies Protractor on how to set up the Selenium Server, how to set up the browsers, which test framework to use, and which tests to run. The users can edit it to include custom configurations.

41. Write code to check if an element by id exists on a web page in Protractor.

Ans: Here is the code that checks for an element by id on a web page in Protractor.

element.all(by.id("elementId")).count().then(function(matches){

if(matches != 0){

console.log("Element exists")

}else{

console.log("Element does not exist")

}

})

42. What is the use of browser.refresh in Protractor?

Ans: The browser.refresh is used to make a full reload of the current page. It also loads the mock modules before Angular. It assumes that the current application is in Angular, and it waits for angular to load before executing the next command. 

43. How can we handle alerts and what are the methods of Alert Class in Protractor?

Ans: To handle alerts on a web page, we can use Alert Class in Protractor. The Alert Class has the following methods.

  • accept()
  • dismiss()
  • getText()
  • sendKeys()
44. Can you verify if a dropdown is selected or not in angular applications?

Ans: We can use the isSelected() method to check if a dropdown is selected or not in angular applications. This method returns a boolean value, in which 1 represents selected, and 0 represents not selected.

45. Write code to overwrite the current input value of an editable field on the page.

Ans: To overwrite the current input value, we have to clear the existing value first. And then, use sendKeys() to give new value. Here is how we can do it.

let webElement = element(by.id("elementId"));

webElement.clear();

webElement.sendKeys(“New Value”); 

46. What is the default time for a Jasmine spec to fail? Can we change that time?

Ans: The default timeout for a Jasmine spec to fail is 30 seconds. We can change the timeout duration by adding the below line in the conf file of Protractor. 

JasmineNodeOpts: {defaultTimeoutInterval: 
47. Can we run multiple specs in Protractor?

Ans: Yes, we can run multiple specs in Protractor by mentioning them in the spec flag in an array. For instance, if you have two spec files – spec1.js and spec2.js, you can mention as follows.

Specs: ['./spec1.js', 'spec2.js']
48. According to you, what would be the order of browsers in terms of faster implementation in Protractor?

Ans: The HTML Unit Driver provides faster implementation compared to other browsers. It is followed by the Firefox driver and then the IE driver. 

49. Explain the difference between browser.close() and browser.quit() commands?

Ans:

  • browser.close() – It will close the current working web browser window that the user is accessing.
  • browser.quit() – It will close all the web browser windows that the program has opened. 
50. How can we execute a spec file in both chrome and firefox?

Ans: We can execute a spec file in both chrome and firefox by specifying them in a multi capabilities parameter.

shardTestFiles: false,

 

multiCapabilities: [{

  ‘browserName’: ‘chrome’,

} , {

  ‘browserName’: ‘firefox’,

}

Leave a Reply

Your email address will not be published. Required fields are marked *