Monday 2 October 2017

Selenium Super 30 Interview Questions - 2

ad300
Advertisement

 

11. Out of 100 check-boxes listed in the page you have to select a particular check-box with text = "abc". Sequence of check-boxes may change from time to time. Consider check-boxes and text in a tabular form.

One possible solution would be xpath:

selectCheckboxWithLabel(NameofLabel){

driver.findElement(By.xpath

        (".//*[@id='main']/table[1]/tbody/tr/td[2][text()=' NameofLabel ']//preceding-sibling::input[1]")).click

  }

12. Write the sequence of steps required to achieve the following:

In first window click on the link. This will open a new window. Enter some data into the text field and clicks submit. Close the second window and come back to the first window.

Click some button on first window and close it.

 Steps should include:

1.      Click on the link present on the main window

2.      Save the handler for the first window before switching to the new window.

3.      Switch to the new window.

4.      Enter some data on the text field and click submit

5.      Close the second window.

6.      Switch back to the main window before accessing any element on that window.

7.      Close the window.

13. Write the sequence of steps to access the element present in a Frame within a Frame.

                              WebElement OuterFrame = driver.findElement(By.id("Frame1")); 

                              //now use the switch command

                              driver.switchTo().frame(OuterFrame); 

                              //Find Frame2

                              WebElement InnerFrame = driver.findElement(By.id("Frame2"));

                              //now use the switch command

                              driver.switchTo().frame(InnerFrame);

                              //Switch back to the main window

                              driver.switchTo().defaultContent();

14. How to automate/capture the mouse hovering sequence. Write the steps

WebElement element = driver.findElement(By.linkText("Product Category"));

Actions action = new Actions(driver);

action.moveToElement(element).moveToElement(driver.findElement(By.linkText("linktext"))).click().build().perform();

15. How one can upload the file without using any external tool in selenium web-driver.

driver.findElement(By.xpath(“input field”)).sendKeys(“path of the file which u want to upload”);

16. Difference between web-based and window-based pop-up. How one can handle these pop-ups.

There are two types of alerts that we would be focusing on majorly:

1.    Windows based alert pop ups( Like Print Dialog )

2.    Web based alert pop ups (Alert box/ Pop up box/ confirmation Box/ Prompt/ Authentication Box)

As we know that handling windows based pop ups is beyond WebDriver’s capabilities, thus we need  some third party utilities to handle window pop ups(like Autoit, Robot etc.)

Handling web based pop-up box

WebDriver offers the users with a very efficient way to handle these pop ups using Alert interface.

There are the four methods that we would be using along with the Alert interface.

1) void dismiss()  The dismiss() method clicks on the “Cancel” button as soon as the pop up window appears.
2) void accept()  The accept() method clicks on the “Ok” button as soon as the pop up window appears.
3) String getText()  The getText() method returns the text displayed on the alert box.
4) void sendKeys(String stringToSend)  The sendKeys() method enters the specified string pattern into the alert box.

 

Object Creation for Alert class:

v  Alert alert = driver.switchTo().alert();

We create a reference variable for Alert class and references it to the alert.

v  Switch to Alert
Driver.switchTo().alert();
The above command is used to switch the control to the recently generated pop up window.

v  Accept the Alert
alert.accept();
The above command accepts the alert thereby clicking on the Ok button.

v Reject the Alert
alert.dismiss();
The above command closes the alert thereby clicking on the Cancel button and hence the operation should not proceed.

17. How would you test a Captcha Code? Is it possible to test it?

Captcha code was introduced in order to prevent from the robot or automation codes. There is no option for automating the Captcha code.

v  You can give a wait time for the automation, so that the user can enter the captcha code.

v  If the project is in testing URL means, you can request your system admin and developer to disable the captcha validation.

Developers will generate a random value for captcha, and they will convert the value into image as well as they will store the value in session for comparing the entered input is matching with the captcha code.

So If possible, you can take that session value and give as the input.

Usually most of the companies either use their own captchas or one of the third party captchas (GooglejQuery plugins) in the user registration page of their sites .So these pages can't be automated fully. In fact Captcha itself is implemented to prevent automation. As per official captcha site

A CAPTCHA is a program that protects websites against bots  by generating and grading tests that humans can pass but current computer programs cannot.

Captchas are not breakable but there are some third party captchas that can be breakable and one of the example for it is "jQuery Real Person" captcha .

18. How would you take a screen shot for the failed test case? How does it work and where have you kept your code to capture the code in your framework?

In order to take screenshot in case of test failure we will use AfterMethod annotation of TestNG. In the AfterMethod annotation we will use ITestResult interface's getStatus() method that returns the test result and in case of failure we can use the above commands to take screenshot

@AfterMethod

public void takeScreenShotOnFailure(ITestResult testResult) throws IOException {

               if (testResult.getStatus() == ITestResult.FAILURE) { System.out.println(testResult.getStatus());

                              File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

                              FileUtils.copyFile(scrFile, new File("D:\\testScreenShot.jpg"));

    }

}

Location of this code depends on framework to framework. We need to dig more and get the design and location for screenshot based on their framework.

19. How are you reading the data from excel. Where are you keeping your data read from the excel when executing the test cases. How are you managing to execute the same test case with different set of data?

1.        FileInputStream fis = new FileInputStream(“path of excel file”);

    Workbook wb = WorkbookFactory.create(fis);

    Sheet s = wb.getSheet(“sheetName”);

    String value = s.getRow(rowNum).getCell(cellNum).getStringCellValue();

2.      Depends on framework to framework how where and how candidates are storing the data. Whether its Array List or HashMap candidate should be able to explain their logic and write a dummy code for the same.

3.      Should explain Logic to execute same test case with different data or TestNG annotation to achieve the same functionality.

20. Difference between findelement and findelements. What are their return types?

  • findElement() method:

ü  We need to use findElement method frequently in our webdriver software test case because this is the only way to locate any element in webdriver software testing tool.

ü  findElement method is useful to locating targeted single element.

ü  If targeted element is not found on the page then it will throw NoSuchElementException.

  • findElements() method:

ü  We are using findElements method just occasionally.

ü  findElements method will return list of all the matching elements from current page as per given element locator mechanism.

ü  If not found any element on current page as per given element locator mechanism, it will return empty list.

 

 

Share This
Previous Post
Next Post

Welcome to my blog, I am Subhash Junas, I have been working on Core Java, Ruby, Selenium, Cucumber and on various automation technologies from past couple of years. I love to work on new challenges, solving problems and obstacles.

0 comments: