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?
 
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

Leave a Reply

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