15.A. Selenium Interview Questions 2
15.A. Selenium Interview Questions 2
are skipped
(“txtSelenium”)).getText ());
Verify: If Verify fails, the test will be continue executing rest of the test cases
and logging the failure
Code:
JavascriptExecutor j=(JavascriptExecutor) driver;
WebElement w = driver.findElement(By.xpath("//*[text()='Live
Demo']")); j.executeScript("arguments[0].scrollIntoView(true)",
w);
4. Explain Robot class and write a code?
5. How will you handle windows based popup , other than robot class?
We can handle window based popup by using AutoIt
6. Assume you launching IE browser you facing protected mode
Exceptions, how you solve that?
Go to Internet option in IE security unchecked “Enable Protected mode”
7. WebDriver driver=new Firefoxdriver() Explain?
WebDriver –Interface.
FirefoxDriver-class.
Driver-Object.
<dependency>
<groupId>org.seleniumhq.selenium</gr
oupId> <artifactId>selenium-
java</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId
> <version>3.8.1</version>
<scope>test</scope>
</dependency
13.Write a code for multiple windows handling?
public class Dummy5 {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver",
"C:/Users/siva/workspace/Selenium/driver/geckodriver.exe")
; WebDriver driver =new FirefoxDriver();
driver.get("https://www.hdfcbank.com/");
driver.findElement(By.xpath(".//*[@id='cee_closeBtn']/img")).click()
; String p = driver.getWindowHandle();
System.out.println(p);
driver.findElement(By.xpath(".//*[@id='loginsubmit']")).click();
Set<String> all = driver.getWindowHandles();
for (String x : all) {
System.out.println(x);
if(!p.equals(x)){
driver.switchTo().window(x)
; Thread.sleep(3000);
driver.findElement(By.xpath("html/body/div[4]/div[2]/div[1]/a")).click();
Thread.sleep(2000);
driver.close();
}
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}
}
15. If u are joined newly here, what are all software and tools u need for automation
1. Eclipse
2. JDK
3. Selenium
4. Drivers for browsers
5. Git url
6. Maven
16.Automate gmail account check the number o messages in inbox
System.out.println(inboxDetails.getText());
switch (currentCell.getCellType()) {
case Cell.CELL_TYPE_STRING:
mapDatas.put(headerRow.getCell(j).getStringCellValue()
, currentCell.getStringCellValue());
break;
case Cell.CELL_TYPE_NUMERIC:
mapDatas.put(headerRow.getCell(j).getStringCellValue(),
String.valueOf(currentCell
.getNumericCellValue()));
break;
}
}
mapDatasList.add(mapDatas);
}
// System.out.println(mapDatasList);
String s = mapDatasList.get(1).get("Username");
String s1 = mapDatasList.get(1).get("Password");
System.out.println(s);
System.out.println(s1);
} catch (Throwable e) {
e.printStackTrace();
}
REGRESSION TESTING is to confirm that a recent code change has not affected
existing features or ffunctionalities.
5. Priority: High
6. Severity: Major
25.If I am having 2 scenarios, first two steps are same in both scenarios now how do I
handle effectively
Using background we can handle this, mention the first two repeated steps
in a background
26. If I am having TestNG annotations like this @BeforeTest
@BeforeMethod
@Test
@Test1
@Test2
Tell me the execution order
@BeforeTest
@BeforeMethod
@Test
@BeforeMethod
@Test1
@BeforeMethod
@Test2
Priority
Priority is defined as the order in which a defect should be fixed. Higher the
priority the sooner the defect should be resolved.
Low
Medium
High
Severity
Defect Severity is defined as the degree of impact that a defect has on the
operation of the product i.e. its not going to affect the functionality
o Critical
o Major
o
Moderate
o Minor
o Cosmetic
27. Tell me one example which is very low severity with a high priority
A very low severity with a high priority: A logo error for any shipment website,
can be of low severity as it not going to affect the functionality of the website but can
be of high priority as you don't want any further shipment to proceed with wrong
logo.
28.INput[Id="123"]>/
L1='541'
L2='541'
L3='541'
POM
JUnit
Data Driven
Cucumber
30. Windows handling scenario: Like if I am currently in main window , first I
have to close 2nd window then move to 3rd window and need to print "we
are in 3rd window" again move to 4th window and print "4th window" then
switch back to main window ?
}
driver.switchTo().defaultContent();}
31. Difference between window and alerts?
ALERTS:
If we click a login or any button one pop-up will show like OK or Cancel.
It has 3 types,
1. Simple Alert
2. Confirm pop-up
3. Prompt pop-up
WINDOW;
if we click login button, one separate window will open.
We have to switch from parent window to child window then only we can automate
partialLinkText:
driver.quit();
}
Syntax:
driver.manage().timeouts().implicitlyWait(time, TimeUnit.SECONDS);
Ex:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Explicit wait:
1. The explicit wait is used to tell the Web Driver to wait for particular
element to certain conditions (Expected Conditions) or the maximum time
exceeded before throwing an exception.
2.The explicit wait is an intelligent kind of wait, but it can be applied
only for specified elements.
3.Explicit wait gives better options than an implicit.
4.Once we declare explicit wait we have to use "ExpectedCondtions" or
we can configure how frequently we want to check the condition using
Fluent Wait.
Syntax:
connection? JDBC
Connection Steps:
Load driver
Connect to database
Write sql query
Prepare the statement
Set the values
Execute query
1.TestNG allows us to execute of test cases based on group. Let‟s take a scenario
where we have created two set of groups “Regression” & “Sanity”. If we want to
execute the test cases under Sanity group then it is possible in TestNG framework.
2.Parallel execution of Selenium test cases is possible in TestNG.
3.As method name constraint is present in JUnit, such method name constraint
is not present in TestNG and you can specify any test method names.
4.TestNG supports following three 3 additional setUp/tearDown
level: @Before/AfterSuite, @Before/AfterTest and
@Before/AfterGroup.
5.TestNG do not require extend any class.
6.TestNG allows us to define the dependent test cases each test case is
independent to other test case.
42.You are not working parallel execution in junit
1. Collect all the links in the web page based on <a> tag.
2. Send HTTP request for the link and read HTTP response code.
3. Find out whether the link is valid or broken based on HTTP response code.
4. Repeat this for all the links captured.
Selenium WebDriver is a web automation framework that allows you to execute your
tests against different browsers,
WebDriver supports programming languages like java,.net, PHP , python etc.
WebDriver can support HtmlUnit browser
46. Assume one web page, in this page we have to check font color, font size and font
format. How will you automate
1.Sometimes you need to read font properties like font size, font color, font family,
font background color etc.. during WebDriver test case execution. Selenium
WebDriver Is very wast API and It has many built In methods to perform very small
small operations on web page.
2.We can read the font properties in selenium webdriver using .getCssValue() method
Example program :
@BeforeTest
public void setup() throws Exception
{ driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://only-testing-blog.blogspot.in/2014/05/login.html");
}
@Test
public void readFontProperty(){
//Locate text string element to read It's font properties.
WebElement text = driver.findElement(By.xpath("//h1[contains(.,'Example Login Page')]"));
47.Define Bug
Lifecycle? New:
When a defect is logged and posted for the first time. It‟s state is
given as new.
Assigned:
After the tester has posted the bug, the lead of the tester approves that the bug is genuine
and he assigns the bug to corresponding developer and the developer team. Its state
given as assigned.
Open:
At this state the developer has started analyzing and working on the
defect fix.
Fixed:
When developer makes necessary code changes and verifies the changes then he/she can
make bug status as „Fixed‟ and the bug is passed to testing team.
Pending retest:
After fixing the defect the developer has given that particular code for retesting to the
tester. Here the testing is pending on the testers end. Hence its status is pending retest.
Retest:
At this stage the tester do the retesting of the changed code which developer has given
to him to check whether the defect got fixed or not.
Verified:
The tester tests the bug again after it got fixed by the developer. If the bug is not present
in the software, he approves that the bug is fixed and changes the status to “verified”.
Reopen:
If the bug still exists even after the bug is fixed by the developer, the tester
changes the status to “reopened”. The bug goes through the life cycle once again.
Closed:
Once the bug is fixed, it is tested by the tester. If the tester feels that the
bug no longer exists in the software, he changes the status of the bug to
“closed”.
This state means that the bug is fixed, tested and approved.
Duplicate:
If the bug is repeated twice or the two bugs mention the same concept of the
bug, then one bug status is changed to “duplicate“.
Rejected:
If the developer feels that the bug is not genuine, he rejects the bug. Then the
state of the bug is changed to “rejected”.
Deferred:
The bug, changed to deferred state means the bug is expected to be fixed in
next releases. The reasons for changing the bug to this state have many factors. Some of
them are priority of the bug may be low, lack of time for the release or the bug may not
have major effect on the software.
Not a bug:
The state given as “Not a bug” if there is no change in the functionality of the
application. For an example: If customer asks for some change in the look and field of
the application like change of colour of some text then it is not a bug but just some
change in the looks of the application.
1.Selenium Webdriver
2.AutoIT editor and element identifier
3.The window that you want to automate
58.I have click the button then I write it for switch to alert but alert is not present how
do u handle
We can handle it by using try catch block
Then we can wait until alert is present by using alertIsPresent(), then we can switch
to alert
Ex:
Public void checkAlert(){
try{
60..If 4 numbers of window named with w1 as parent window and 3 child window are
w2,w3,w4 are there. how will you switch from parent wind to directly w4 child window
without using index?
public class NewUserActivationlv {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:/Users/Desktop/Selenium/Driver/chrom
edriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.example.in/RetailLogin.html");
driver.manage().window().maximize();
String PID = driver.getWindowHandle();
System.out.println(PID);
driver.findElement(By.linkText("New User Login")).click();
Set<String> s1 =
driver.getWindowHandles(); List<String>
s = new ArrayList<String>();
s.addAll(s1);
System.out.println(s);
driver.switchTo().window(s.get(
4));
61. What test case can be automated? in regression testing how will you choose
which test cases need to be automated?
What are the criteria to automate test case?
Regression test case and smoke test cases can be automated.
Criteria for automate test case:
1. Repetitive tests that run for multiple builds.
2. Tests that tend to cause human error.
3. Tests that require multiple data sets.
4. Frequently used functionality that introduces high risk conditions.
5. Tests that are impossible to perform manually.
6. Tests that run on several different hardware or software platforms and
configurations.
7.Tests that take a lot of effort and time when manual testing.
Statement: Example
//Creating The Statement Object
Callable Example:
//Creating CallableStatement object
CallableStatement cstmt = con.prepareCall("{call anyProcedure(?, ?, ?)}");
//Use cstmt.setter() methods to pass IN parameters
//Use cstmt.registerOutParameter() method to register OUT parameters
//Executing the CallableStatement
cstmt.execute();
//Use cstmt.getter() methods to retrieve the result returned by the stored procedure
c. We will use Gherkin language in feature file to write user stories in more efficient
way using Gherkin keywords like
i. Scenario
ii. Given
iii. When
iv. Then
v. And
vi. But
d. Step Definition file contains the actual code to execute.
v. In Test Runner class, we will use JUnit annotations like @Runwith,
@CucumberOptions
@ CucumberOptions mention the feature file in feature and step Definition in glue.
1. @Test: Annotation lets the system know that the method annotated as @Test is a test
method. There can be multiple test methods in a single test script.
2. @Before: Method annotated as @Before lets the system know that this method shall be
executed every time before each of the test method.
3. @After: Method annotated as @After lets the system know that this method shall be
executed every time after each of the test method.
4. @BeforeClass: Method annotated as @BeforeClass lets the system know that this
method shall be executed once before any of the test method.
5. @AfterClass: Method annotated as @AfterClass lets the system know that this method
shall be executed once after any of the test method.
6. @Ignore: Method annotated as @Ignore lets the system know that this method shall not
be executed.
No need to write main method in junit, because you can always call a JUnit runner to run
a test case class as a system command.
But If you want to know how to call a JUnit runner in a main() method,
Sample code:
public static void main(String[] args) {
junit.textui.TestRunner.run(DirListerTest.class);}
6.Explain about TestNG?
TestNG
TestNG is a framework, it is an advance of Junit
TestNG (NG - New Generation), we can overcome all the disadvantages of Junit by
using TestNG
TestNG has various class, interface and methods
Advantages
Order is possible, i.e. we can prioritize tests by using priority attribute
It will give default reports like html, xml format
Cross browser testing and Parallel browser execution is possible
Less configuration
We can control execution by using annotations
7.Parellel test execution on TestNG.?
Browsers will open almost simultaneously and your test will run in parallel.
Now just set the ‘parallel‘ attribute to ‘tests‘ in the xml
8.Difference between @BeforeMethod, @BeforeClass and @BeforeTest
@BeforeMethod: The annotated method will be run before each test method.
@BeforeClass: The annotated method will be run before the first test method in the current
class is invoked.
@BeforeTest: The annotated method will be run before any test method belonging to the
classes inside the <test> tag is run.
9. Difference between JUnit and TestNG
Configuration of parameterized test is very easy in TestNG where as it is a tough in
JUnit.
Group test is supported by TestNG and JUnit does not support it.
Dependency test configuration is not possible in JUnit but it is possible in TestNG
@Before test, @After test, @Before suit, @After suit, @before groups, @After groups
are supported by TestNG and not by JUnit.
TestNG supports test prioritization and parallel tests but Junit does not support it.
10. Where is the test report saved in testng
You have to first run the tests by running the testng.xml as TestNG suite.
Then after that refresh the project.
Now goto the test-output folder -->html-->index.html (Open with Web Browser)
12. How will you execute parallel browsing execution, where it is mentioned
Browsers will open almost simultaneously and your test will run in parallel.
To execute parallel browsing we should set the ‘parallel‘ attribute to ‘tests‘ in the
xml
It is mentioned in testing.xml
Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |
The Scenario Outline steps provide a template which is never directly run. A Scenario Outline is
run once for each row in the Exam
Jenkins is an leading open source continuous integration server built with Java.
It is used to build and test software projects continuously making it easier to
integrate changes to the project.
Support for scheduled builds & automation test execution.