Accenture Selenium Recently Asked Interview Questions Answers
What are the different types of driver implementation?
AndroidDriver, AndroidWebDriver, ChromeDriver, EventFiringWebDriver, FirefoxDriver, HtmlUnitDriver, InternetExplorerDriver, IPhoneDriver, IPhoneSimulatorDriver, RemoteWebDriver, SafariDriver, WebDriverBackedSelenium
Code for Opening Firefox browser?
Webdriver driver=new FireFoxdriver();
Which repository you have used to store the test scripts?
I have created scripts in excel file and store them in Test cases folder under src .
How to work with radio button in web driver?
We can select the value from the drop down by using 3 methods.
selectByVisibleText – select by the text displayed in drop down
selectByIndex – select by index of option in drop down
selectByValue – select by value of option in drop down
WebElement e = driver.findElement(By.id(“44”));
Select selectElement=new Select(e);
// both of the below statements will select first option in the weblist
selectElement.selectByVisibleText(“xyz”);
selectElement.selectByValue(“1”);
How to work with dynamic web table?
You can get the total number of
tags within a
tag by giving the xpath of the
element by using this function –
List ele = driver.findElements(By.xpath(“Xpath of the table”));
Now you can use a for each loop to loop through each of the tags in the above list and then read each value by using getText() method.
Detail about TestNG Test Output folder.
It is the directory where reports are generated. Every time tests run in a suite, TestNG
creates index.html and other files in the output directory.
In frame if no frame Id as well as no frame name then which attribute I should consider throughout our script.
You can go like this…..driver.findElements(By.xpath(“//iframe”))…
Then it will return List of frames then switch to each and every frame and search for the locator which you want then break the loop
What is object repository?
It is collection of object names their properties, attributes and their values .It maye be excel, XML,property file or text file
TestNG vs. Junit?
Advantages of TestNG over Junit
In Junit we have to declare @BeforeClass and @AfterClass which is a constraint where as in TestNG there is no constraint like this.
Additional Levels of setUp/tearDown level are available in TestNG like @Before/AfterSuite,@Before/AfterTest and @Before/AfterGroup
No Need to extend any class in TestNG.
There is no method name constraint in TestNG as in Junit. You can give any name to the test methods in TestNG
In TestNG we can tell the test that one method is dependent on another method where as in Junit this is not possible. In Junit each test is independent of another test.
Grouping of testcases is available in TestNG where as the same is not available in Junit.
Execution can be done based on Groups. For ex. If you have defined many cases and segregated them by defining 2 groups as Sanity and Regression. Then if you only want to execute the “Sanity” cases then just tell TestNG to execute the “Sanity” and TestNG will automatically execute the cases belonging to the “Sanity” group.
Also using TestNG your selenium test case execution can be done in parallel.
What is the difference between @beforemethod and @beforeclass.
In JUnit4 @Before is used to execute set of preconditions before executing a test.
For example, if there is a need to open some application and create a user before
executing a test, then this annotation can be used for that method. Method that is
marked with @Before will be executed before executing every test in the class.
If a JUnit test case class contains lot of tests which all together need a method
which sets up a precondition and that needs to be executed before executing the
Test Case class then we can utilise “@BeforeClass” annotation.
Which is more preferable xpath or CSS?
CSS Selector
How to find out all the links in webpage?
List<WebElement> allLinks = driver.findElements(By.tagName(“a”));
How we will configure the Parallel browser testing in testng.xml?
<suite name=”Parallel test suite” parallel=”tests”>
Explain about TestNG – its listeners?
ITestListener has following methods
OnStart – OnStart method is called when any Test starts.
onTestSuccess– onTestSuccess method is called on the success of any Test.
on test failure– on test failure method is called on the failure of any Test.
onTestSkipped – onTestSkipped method is called on skipped of any Test.
onTestFailedButWithinSuccessPercentage – method is called each time Test fails but is within success percentage.
onFinish – onFinish method is called after all Tests are executed
Write a Syntax to take the screenshot?
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//The below method will save the screen shot in d drive with name “screenshot.png”
FileUtils.copyFile(scrFile, new File(“D:\\screenshot.png”));
How to find out all the frames in a webpage?
List<WebElement> ele = driver.findElements(By.tagName(“frame”));
System.out.println(“Number of frames in a page :” + ele.size());
How to handle cookies?
In Selenium Webdriver interact with cookies with below built-in methods
driver.manage().getCookies(); // Return The List of all Cookies
driver.manage().getCookieNamed(arg0); //Return specific cookie according to name
driver.manage().addCookie(arg0); //Create and add the cookie
driver.manage().deleteCookie(arg0); // Delete specific cookie
driver.manage().deleteCookieNamed(arg0); // Delete specific cookie according Name
driver.manage().deleteAllCookies(); // Delete all cookies
What is Selenium Grid?
Selenium Grid is a tool used together with Selenium RC to run parallel tests across different machines and different browsers all at the same time. Parallel execution means running multiple tests at once.
Features:
Enables simultaneous running of tests in multiple browsers and environments.
Saves time enormously.
Utilizes the hub-and-nodes concept. The hub acts as a central source of Selenium commands to each node connected to it.
Difference between find elements and find element?
FINDELEMENT() METHOD:
FindElement method is used to access a single web element on a page. It returns the first matching element. It throws a NoSuchElementException exception when it fails to find If the element.
Syntax:
driver.findElement(By.xpath(“Value of Xpath”));
FINDELEMENTS() METHOD:
FindElements method returns the list of all matching elements. The findElement method throws a NoSuchElementException exception when the element is not available on the page. Whereas, the findElements method returns an empty list when the element is not available or doesn’t exist on the page. It doesn’t throw NoSuchElementException.
Syntax:
List link = driver.findElements(By.xpath(“Value of Xpath”));
Explain about softAssert and HardAssert?
Asserts are used to perform validations in the test scripts.
There are two types of Assert:
Hard Assert
Soft Assert
When an assert fails the test script stops execution unless handled in some form. We call general assert as Hard Assert.
Hard Assert – Hard Assert throws an AssertExceptionimmediately when an assert statement fails and test suite continues with next @Test.
The disadvantage of Hard Assert – It marks method as fail if assert condition gets failed and the remaining statements inside the method will be aborted.
To overcome this we need to use Soft Assert. Let’s see what is Soft Assert.
Soft Assert – Soft Assert collects errors during @Test. Soft Assert does not throw an exception when an assert fails and would continue with the next step after the assert statement.
If there is any exception and you want to throw it then you need to use assertAll() method as a last statement in the @Test and test suite again continue with next @Test as it is.
We need to create an object to use Soft Assert which is not needed in Hard Assert.
How to Start Jenkins in command Promt?
D:\>Java –jar Jenkins.war
What is the latest version of Jenkins?
Jenkins 2.114
What is Page Object Model?
Page Object Model Framework has now a days become very popular test automation framework in the industry and many companies are using it because of its easy test maintenance and reduces the duplication of code.
The main advantage of Page Object Model is that if the UI changes for any page, it don’t require us to change any tests, we just need to change only the code within the page objects (Only at one place).
The Page Object model provides the following advantages.
There is clean separation between test code and page specific code such as locators (or their use if you’re using a UI map) and layout.
There is single repository for the services or operations offered by the page rather than having these services scattered throughout the tests.
What is the default port for selenium Grid?
The default port used by the hub is 4444.
What are the different types of driver implementation?
AndroidDriver, AndroidWebDriver, ChromeDriver, EventFiringWebDriver, FirefoxDriver, HtmlUnitDriver, InternetExplorerDriver, IPhoneDriver, IPhoneSimulatorDriver, RemoteWebDriver, SafariDriver, WebDriverBackedSelenium
Code for Opening Firefox browser?
Webdriver driver=new FireFoxdriver();
Which repository you have used to store the test scripts?
I have created scripts in excel file and store them in Test cases folder under src .
How to work with radio button in web driver?
We can select the value from the drop down by using 3 methods.
selectByVisibleText – select by the text displayed in drop down
selectByIndex – select by index of option in drop down
selectByValue – select by value of option in drop down
WebElement e = driver.findElement(By.id(“44”));
Select selectElement=new Select(e);
// both of the below statements will select first option in the weblist
selectElement.selectByVisibleText(“xyz”);
selectElement.selectByValue(“1”);
Accenture Selenium Recently Asked Interview Questions Answers |
How to work with dynamic web table?
You can get the total number of
tags within a
tag by giving the xpath of the
element by using this function –
List ele = driver.findElements(By.xpath(“Xpath of the table”));
Now you can use a for each loop to loop through each of the tags in the above list and then read each value by using getText() method.
Detail about TestNG Test Output folder.
It is the directory where reports are generated. Every time tests run in a suite, TestNG
creates index.html and other files in the output directory.
In frame if no frame Id as well as no frame name then which attribute I should consider throughout our script.
You can go like this…..driver.findElements(By.xpath(“//iframe”))…
Then it will return List of frames then switch to each and every frame and search for the locator which you want then break the loop
What is object repository?
It is collection of object names their properties, attributes and their values .It maye be excel, XML,property file or text file
TestNG vs. Junit?
Advantages of TestNG over Junit
In Junit we have to declare @BeforeClass and @AfterClass which is a constraint where as in TestNG there is no constraint like this.
Additional Levels of setUp/tearDown level are available in TestNG like @Before/AfterSuite,@Before/AfterTest and @Before/AfterGroup
No Need to extend any class in TestNG.
There is no method name constraint in TestNG as in Junit. You can give any name to the test methods in TestNG
In TestNG we can tell the test that one method is dependent on another method where as in Junit this is not possible. In Junit each test is independent of another test.
Grouping of testcases is available in TestNG where as the same is not available in Junit.
Execution can be done based on Groups. For ex. If you have defined many cases and segregated them by defining 2 groups as Sanity and Regression. Then if you only want to execute the “Sanity” cases then just tell TestNG to execute the “Sanity” and TestNG will automatically execute the cases belonging to the “Sanity” group.
Also using TestNG your selenium test case execution can be done in parallel.
What is the difference between @beforemethod and @beforeclass.
In JUnit4 @Before is used to execute set of preconditions before executing a test.
For example, if there is a need to open some application and create a user before
executing a test, then this annotation can be used for that method. Method that is
marked with @Before will be executed before executing every test in the class.
If a JUnit test case class contains lot of tests which all together need a method
which sets up a precondition and that needs to be executed before executing the
Test Case class then we can utilise “@BeforeClass” annotation.
Which is more preferable xpath or CSS?
CSS Selector
How to find out all the links in webpage?
List<WebElement> allLinks = driver.findElements(By.tagName(“a”));
How we will configure the Parallel browser testing in testng.xml?
<suite name=”Parallel test suite” parallel=”tests”>
Explain about TestNG – its listeners?
ITestListener has following methods
OnStart – OnStart method is called when any Test starts.
onTestSuccess– onTestSuccess method is called on the success of any Test.
on test failure– on test failure method is called on the failure of any Test.
onTestSkipped – onTestSkipped method is called on skipped of any Test.
onTestFailedButWithinSuccessPercentage – method is called each time Test fails but is within success percentage.
onFinish – onFinish method is called after all Tests are executed
Write a Syntax to take the screenshot?
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//The below method will save the screen shot in d drive with name “screenshot.png”
FileUtils.copyFile(scrFile, new File(“D:\\screenshot.png”));
How to find out all the frames in a webpage?
List<WebElement> ele = driver.findElements(By.tagName(“frame”));
System.out.println(“Number of frames in a page :” + ele.size());
How to handle cookies?
In Selenium Webdriver interact with cookies with below built-in methods
driver.manage().getCookies(); // Return The List of all Cookies
driver.manage().getCookieNamed(arg0); //Return specific cookie according to name
driver.manage().addCookie(arg0); //Create and add the cookie
driver.manage().deleteCookie(arg0); // Delete specific cookie
driver.manage().deleteCookieNamed(arg0); // Delete specific cookie according Name
driver.manage().deleteAllCookies(); // Delete all cookies
What is Selenium Grid?
Selenium Grid is a tool used together with Selenium RC to run parallel tests across different machines and different browsers all at the same time. Parallel execution means running multiple tests at once.
Features:
Enables simultaneous running of tests in multiple browsers and environments.
Saves time enormously.
Utilizes the hub-and-nodes concept. The hub acts as a central source of Selenium commands to each node connected to it.
Difference between find elements and find element?
FINDELEMENT() METHOD:
FindElement method is used to access a single web element on a page. It returns the first matching element. It throws a NoSuchElementException exception when it fails to find If the element.
Syntax:
driver.findElement(By.xpath(“Value of Xpath”));
FINDELEMENTS() METHOD:
FindElements method returns the list of all matching elements. The findElement method throws a NoSuchElementException exception when the element is not available on the page. Whereas, the findElements method returns an empty list when the element is not available or doesn’t exist on the page. It doesn’t throw NoSuchElementException.
Syntax:
List link = driver.findElements(By.xpath(“Value of Xpath”));
Explain about softAssert and HardAssert?
Asserts are used to perform validations in the test scripts.
There are two types of Assert:
Hard Assert
Soft Assert
When an assert fails the test script stops execution unless handled in some form. We call general assert as Hard Assert.
Hard Assert – Hard Assert throws an AssertExceptionimmediately when an assert statement fails and test suite continues with next @Test.
The disadvantage of Hard Assert – It marks method as fail if assert condition gets failed and the remaining statements inside the method will be aborted.
To overcome this we need to use Soft Assert. Let’s see what is Soft Assert.
Soft Assert – Soft Assert collects errors during @Test. Soft Assert does not throw an exception when an assert fails and would continue with the next step after the assert statement.
If there is any exception and you want to throw it then you need to use assertAll() method as a last statement in the @Test and test suite again continue with next @Test as it is.
We need to create an object to use Soft Assert which is not needed in Hard Assert.
How to Start Jenkins in command Promt?
D:\>Java –jar Jenkins.war
What is the latest version of Jenkins?
Jenkins 2.114
What is Page Object Model?
Page Object Model Framework has now a days become very popular test automation framework in the industry and many companies are using it because of its easy test maintenance and reduces the duplication of code.
The main advantage of Page Object Model is that if the UI changes for any page, it don’t require us to change any tests, we just need to change only the code within the page objects (Only at one place).
The Page Object model provides the following advantages.
There is clean separation between test code and page specific code such as locators (or their use if you’re using a UI map) and layout.
There is single repository for the services or operations offered by the page rather than having these services scattered throughout the tests.
What is the default port for selenium Grid?
The default port used by the hub is 4444.
Post a Comment