Amazon Selenium Recently Asked Interview Questions Answers

What is the difference between driver.close() and driver.quit() command?

close(): This method is used to close the current active window of the browser.

quit(): This method is used to close all the associated windows of the browser that are opened.

How to handle Javascript Alerts or web-based pop-ups?

To handle Javascript Alerts, WebDriver provides an Interface called Alert.

First, we need to switch the driver focus to alerts.

Syntax:

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

alert.getText() – The getText() method retrieves the text displayed on the alert box.

alert.accept() – The accept() method clicks on the “Ok” button as soon as the pop-up window appears.

alert.dismiss() – The accept() method clicks on the “Cancel” button as soon as the pop-up window appears.

alert.sendKeys(String stringToSend) – The sendKeys() method enters the specified string pattern into the alert box.
Amazon Selenium Recently Asked Interview Questions Answers
Amazon Selenium Recently Asked Interview Questions Answers

How to capture screenshot in WebDriver?

public String getScreenshot() throws Exception {

try {

driver.get(“https://www.google.co.in/”);

driver.findElement(By.linkText(“Gmail”)).click();

return “Pass”;

}

catch(Exception e) {

DateFormat dateFormat = new SimpleDateFormat(“dd-MM-yyyy HH-mm-ss”);

Date dt = new Date();

File screenshotFile = ((TakesScreenshot) d).getScreenshotAs         (OutputType.FILE);

FileUtils.copyFile(screenshotFile, new File(“F:\\Selenium_Scripts_Feb17\\Results\\”+dateFormat.format(dt)+”.png”));

return “Fail”;

}

}

Write a code to login into any site showing uthentication pop-up for username and password?

//Pass Username and Password in URL itself

driver.get(“http://username:password@www.xyz.com”);

How do you send ENTER key?

driver.findElement(By.id(“email”)).sendKeys(Keys.ENTER);

How do you access Firefox profiles in WebDriver?

//create object of ProfilesIni class which holds all the profiles of FF

ProfilesIni pr=new ProfilesIni():

//To load the profile

FirefoxProfile fp=pr.get(“user”);

WebDriver driver=new FirefoxDriver(fp);

driver.get(“http://google.com”);

What are the different types of Waits or Synchrinization commands in WebDriver?

Usually, the time delay between two webdriver elements is 0 milliseconds but the application speed varies based on different factors:

Internet speed
Server response time
System configuration
To avoid the timing errors(Synchronization errors) between the tool (webdriver) and application, we take the help of Synchronization commands.

Implicit Wait: It is used to define wait for all the elements of WebDriver.
Syntax:

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Explicit Wait: It is used to define wait for specific element of WebDriver.
Syntax:

WebDriverWait wait=new WebDriverWait(driver, 30);

wait.until(ExpectedConditions.elementToBeClickable(By.linkText(“Gmail”)));

Write a syntax to scroll down a page in selenium?

JavascriptExecutor jsx=((JavascriptExecutor) driver);

jsx.executeScript(“window.scrollBy(0,500)”,””);

How to check if text is present on a web page?

String text=”Selenium”;

boolean isTextPresent=(driver.getPageSource()).contains(text);

System.out.println(text+” is present in the web page”);

What are the different exceptions in Selenium web driver?

The different exceptions in Selenium web drivers are

WebDriverException

ElementNotVisibleException

NoAlertPresentException

NoSuchWindowException

NoSuchElementException

TimeoutException

StaleElementReferenceException

How to handle MouseHover?

By using moveToElement() method in Actions class

//Create an object to Actions class

Actions action = new Actions(driver);

action.moveToElement(element);

How to handle Frames?

driver.switchTo().frames(id/name/index/loactor);

How to switch from child frame to parent frame?

To switch back from child frame to parent frame use method parentFrame()

Syntax:

driver.switchTo().parentFrame();

Explain how to switch back from a frame?

To switch back from a frame use method defaultContent()

Syntax:

driver.switchTo().defaultContent();

What is the difference between “/” and “//”

Single Slash “/” – Single slash is used to create XPath with absolute path i.e. it locates the element from the root node.

Example:

/html/body/div[2]/div[4]/table/tbody/tr[4]/td/span

Double Slash “//” – Double slash is used to create XPath with relative path i.e.  it locates the element from the current node.

Example:

//input[@name=’email’]

What is the difference between Assert and Verify in Selenium?

There is no difference between Assert and Verify in a positive scenario.

Assert: If the assert condition is true then the program control will execute the next test step but if the condition is false, the execution will stop and further test step will not be executed.

Verify: If the verify condition is true then the program control will execute the next test step but if the condition is false, the execution of the current step will be skipped and further test step will be executed.

What is the super interface of WebDriver?

SearchContext  is the super interface of WebDriver

How many ways can we load a web page?

We can load a webpage(url) in two ways:

driver.get(“URL”);
driver.navigatr().to(“URL”);

If Default port no is busy how to change port no?

We can use any port number which is valid.. First create an object to remote control configuration.
Use ‘setPort’ method and provide valid port number(4545,5555,5655, etc).. There after attach this
remote control configuration object to selenium server..i.e
RemoteControlConfiguration r= new RemoteControlConfiguration();
r.setPort(4567);
SeleniumServer s= new SeleniumServer(r);

Does Selenium support https protocols?

Yes

Majorly asked test scenario with framework in Interviews?

Majorly asked are:

Login for Gmail scenario
Goggle search and finding no of results
Downloading a file and save it
Checking mails and deleting them
Do shopping in flipkart.com

Selenium support mobile applications?

No, it is browser automation tool, it only automates Websites opening in mobile browser, and mobile APPs can’t be automated.

What is wraps Driver?

For casting selenium instance to selenium2 (webdriver). wraps driver is used.

Can you explain Junit Annotation? If there are 1000 test cases. 500 test cases are executed. How will you execute the rest of the test cases by using annotation?

The annotations generated with JUnit 4 tests in Selenium are:

@Before public void method() – Will perform the method() before each test. This method can prepare the test
@Test public void method() – Annotation @Test identifies that this method is a test method.environment,e.g. read input data, initialize the class)
@After public void method() – Test method must start with test@Before – this annotation is used for executing a method before

Difference between assert and verify in selenium web driver.

When an “assert” fails, the test will be aborted. Assert is best used when the check value has to pass for the test to be able to continue to run log in.
Where if a “verify” fails, the test will continue executing and logging the failure. Verify is best used to check non critical things. Like the presence of a headline element.

“I want to find the location of “”b”” in the below code, how can I find out without using xpath, name,id, csslocator, index.
a
b
c
• driver.findElement(By.xpath(“//*[contains(text(),’b’)]”)).click(); or
• //div/button[contains(text(),’b’]

How to do Applet testing using selenium?

Please see below URLs:
http://docs.codehaus.org/display/FEST/Selenium
https://code.google.com/p/festselenium/

Name 5 different exceptions you had in selenium web driver and mention what instance you got it and how do you resolve it?

WebDriverException
NoAlertPresentException
NoSuchWindowException
NoSuchElementException
TimeoutException
WebDriverException
WebDriver Exception comes when we try to perform any action on the non-existing
driver.
WebDriver driver = new InternetExplorerDriver();
driver.get(“http://google.com”);
driver.close();
driver.quit();

NoAlertPresentException
When we try to perform an action i.e., either accept() or dismiss() which is not required
at a required place; gives us this exception.
try{
driver.switchTo().alert().accept();
}
catch (NoAlertPresentException E){
E.printStackTrace();
}

NoSuchWindowException
When we try to switch to an window which is not present gives us this exception:
WebDriver driver = new InternetExplorerDriver();
driver.get(“http://google.com”);
driver.switchTo().window(“Yup_Fail”);
driver.close();
In the above snippet, line 3 throws us an exception, as we are trying to switch to an
window that is not present.

Similar to Window exception, Frame exception mainly comes during switching between the frames.
WebDriver driver = new InternetExplorerDriver();
driver.get(“http://google.com”);
driver.switchTo().frame(“F_fail”);
driver.close();
In the above snippet, line 3 throws us an exception, as we are trying to switch to an
frame that is not present.

NoSuchElementException
This exception is thrown when we WebDriver doesn’t find the web-element in the DOM.
WebDriver driver = new InternetExplorerDriver();
driver.get(“http://google.com”);
driver.findElement(By.name(“fake”)).click();

TimeoutException
Thrown when a command does not complete in enough time.
All the above exceptions were handled using try catch exceptions.

How do you manage the code versions in your project?

Using SVN or other versioning tools

Latest version of Firefox and selenium in market and the version on which you are testing which you are testing.

FF Latest version till Dec,2013 for windows7,64 bit :26.0.I use FF 25.0.1 (ur ans. may differ)
Selenium web driver latest version till dec,2013- 2.39.0 I use selenium 2.37 see latest at http://www.seleniumhq.org/download/

How to know all the methods supported in web driver and its syntax.

In Org.openqa.selenium package, web driver interface has all the main methods that can be used in Selenium Web driver
HTTP://docs.seleniumhq.org/docs/03_webdriver.jsp

How do you create html test report from your test script?

I would see below 3 ways:

Junit: with the help of ANT.
TestNG: using inbuilt default.html to get the HTML report. Also XLST reports from ANT, Selenium, TestNG combination.
Using our own customized reports using XSL jar for converting XML content to HTML.

List the browsers, OS supported by the Selenium Windows Linux Mac

IE Y NA NA
FF Y Y Y
Safari Y N Y
Opera Y Y Y
Chrome Y Y Y

Can you explain Selenium Mobile Automation?

Some Good urls’s till the time i write custom document for it.
https://code.google.com/p/selenium/wiki/AndroidDriver
http://manojhans.blogspot.in/2013/08/native-android-apps-automation-with.html

How to highlight an object like qtp/uft does through selenium and java?

public void highlightElement(WebDriver driver, WebElement element) {
for (int i = 0; i < 2; i++)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(“arguments[0].setAttribute(‘style’, arguments[1]);”, element, “color: yellow; border: 2px solid yellow;”);
js.executeScript(“arguments[0].setAttribute(‘style’, arguments[1]);”, element, “”);
}}
Call the highlightElement method and pass webdriver and WebElement which you want to highlight as arguments.


Automation Testing Lifecycle?

Requirement Gathering
Analysis
Designing
Development
Testing
Maintenance.


Post a Comment

Previous Post Next Post