Selenium 3 –
Interview Questions
1)
What is selenium?
Its an open source Web Automation Tool. It supports all
types of web browsers.
2)
Advantages of Selenium?
·
No License fees
·
Supports large number of progremming
language for scripting
·
Support large number of browsers.
·
With Selenium Grid, we can execute
in parallel, ultimately fast execution.
3)
Disadvantages of Selenium?
·
Support only web applications
·
Its free so no support is available
·
No Rich GUI / Lot of programming
skills are required.
4)
What are the flavors of selenium?
Selenium IDE, selenium RC, Selenium WebDriver and Selenium
Grid.
It has four components:
Selenium 1 (Selenium IDE + Selenium RC + Selenium
Grid)
Selenium 2 (Selenium IDE + Selenium RC +
Selenium Grid + Selenium Web Driver)
a) Selenium IDE?
Selenium IDE is a complete
integrated development environment (IDE) for Selenium tests. It is a Firefox
plugin that you can install. It allows recording, editing, and debugging tests.
Scripts are recorded in Selenese, a special test scripting language for
Selenium.
PROS
·
Very easy to se and install.
·
No programming experience is
required.
·
Can export tests to formats usable
in Selenium RC and WebDriver.
·
Has built-in help and test results
reporting module.
CONS
·
Available only in firefox.
·
Designed only to create prototypes
of tests.
·
Test execution is slow compared to
Selenium RC and WebDriver.
b) 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.
c) Selenium WebDriver
WebDriver, unlike Selenium RC, does
not rely on JavaScript for Automation. It controls the browser by directly
communicating with it. At the moment, Selenium RC and WebDriver are merged into
a single framework to form Selenium 2. The supported languages are:
·
Java
·
C#
·
PHP
·
Python
·
Perl
·
Ruby
Prerequisites to run selenium
webdriver are JDK, Eclipse, WebDriver(selenium standalone jar file), browser,
application to be tested.
PROS
·
Simpler installation than RC
·
Communication directly to the
browser
·
No Need for a seperate component
such as RC server.
·
Faster execution time than IDE and
RC.
CONS
·
Installation is more complicated
than IDE
·
Requires programming knowledge
·
Cannot readily support new browsers
5)
Set Up Selenium WebDriver:
a)
Set Up Java
b)
Set Up Eclipse
c)
Set Up WebDriver Client
d)
Configure Eclipse with WebDriver
e)
First Test Case
a) Set Up Java
Why Java is platform independent?
With Java, you can compile source
code on Windows and the compiled code can be executed on any platform running a
JVM. So yes you need a JVM but the JVM can run any compiled code, the
compiled code is platform independent.
The Java Virtual machine (JVM) is the virtual machine that runs
the Java bytecodes. The JVM doesn't understand Java source code, that's why you
compile your *.java files to obtain *.classfiles that contain the bytecodes
understood by the JVM.
The Java Runtime Environment (JRE) provides the libraries, the Java
Virtual Machine, and other components to run applets and applications written
in the Java programming language.
The JDK is a superset of the JRE, and contains everything that is in
the JRE, plus tools such as the compilers and debuggers necessary for
developing applets and applications.
Download and then install JDK from
website http://www.oracle.com.
Please not that you will find two download links for Windows i.e.
·
Windows x86
·
Windows x64
Windows x86 means 32 bit system and
Windows x64 is for 64 bit system. Download as per your Windows requirement.
b) Set Up Eclipse
·
Download Eclipse from
http://www.eclipse.org/downloads, extract and save it in any drive. Run
‘eclipse.exe’ directly so you do not need to install Eclipse.
·
You need to know the type of version
of your OS. If your computer is a 64 bit Windows, select Windows 64 else select
Windows 32 bit.
·
Create a workspace folder where you
will contain all the program files you create.
c) Set Up WebDriver Client
Download WebDriver Java client
driver from http://docs.seleniumhq.org/download/.
d) Configure Eclipse with Selenium
WebDriver
To configure Eclipse with Selenium
WebDriver, we need to perform the following activities:
i.
Launch the Eclipse IDE & Create
a Workspace
ii.
Create a new Project
iii.
Create a new Package
iv.
Create a new Class
v.
Add External libraries to the
project
i)
Launch
the Eclipse IDE & Create a Workspace
You can change it from “Switch Workspace”
ii)
Create
a new Project
Project is
a collection of related code.
·
Create new
Java Project from File > New > Project.
·
Select Java Project and click Next.
·
Then give your Project
name in next wizard and Click on Finish button.
iii)
Create
a new Package
·
Right
click on newly created Project and select New > Package.
·
Give your
Package name ‘automationFramework‘ and click on Finish button.
·
Now you
can see a new package with name ‘automationFramework‘ under project name.
iv)
Create
a new Class
·
Right
click on Package ‘automationFramework‘ and select New > Class.
·
Give your
Class name ‘FirstTestCase‘, check the option ‘public static void main‘ and
click on Finish button.
v)
Add
External libraries to the project
·
Right
click on Project > Select Properties > Java build path. Then navigate to
Libraries tab and click Add External JARs.
·
Add all
jar files downloaded.
Now you are ready to write your
test script in eclipse and run it in WebDriver.
e) First
Test Case
Script 1
package AutomationFramework;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class FirstTestCase {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://newtours.demoaut.com/");
driver.findElement(By.name("userName")).sendKeys("Rajiv");
driver.findElement(By.name("password")).sendKeys("Walia");
driver.findElement(By.name("login")).click();
System.out.println("Successfully
opened a website");
}
}
Script 2
package AutomationFramework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class FirstTestCase {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://iniitian.niit-tech.com/ntless/");
System.out.println("Successfully
opened a website");
}
}
Other Selenium 3 Interview Questions
1)
What are the annotations used in TestNG ?
@Test, @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest,
@BeforeClass, @AfterClass, @BeforeMethod, @AfterMethod.
2)
What is the use of xpath ?
It is used to find the WebElement in web page. It is very
useful to identify the dynamic web elements.
3)
What are different types of locators ?
There are 8 types of locators and all are the static methods
of the By class.
By.id(), By.name(), By.tagName(), By.className(), By.linkText(),
By.partialLinkText(), By.xpath, By.cssSelector().
4)
What is the difference between Assert and Verify?
Assert- it is used to verify the result. If the test case
fail then it will stop the execution of the test case there itself and move the
control to other test case.
Verify- it is also used to verify the result. If the test
case fail then it will not stop the execution of that test case.
5)
How do you launch IE/chrome/FF browser?
//To open IE browser
System.setProperty(“webdriver.ie.driver”,”path of the
iedriver.exe file ”);
WebDriver driver = new InternetExplorerDriver();
//To open Chrome browser
System.setProperty(“webdriver.chrome.driver”,”path of the
chromedriver.exe file ”);
WebDriver driver = new ChromeDriver();
//To open Firefox browser
System.setProperty(“webdriver.gecko.driver”,”path of the
geckodriver.exe file ”);
WebDriver driver = new ChromeDriver();
6)
How do you simulate browser back and forward ?
driver.navigate().back();
driver.navigate().forward();
7)
How do you get the current page URL ?
driver.getCurrentUrl();
8)
What is the difference between ‘/’ and ‘//’ ?
//- it is used to search in the entire structure.
/- it is used to identify the immediate child.
9)
What is the difference between findElement and findElements?
findElement() – it used to find the one web element. It
return only one WebElement type.
findElements()- it used to find more than one web element.
It return List of WebElements.
10)
How do you achieve synchronization in WebDriver ?
We can use implicit wait.
Syntax-
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
11)
How do you clear the contents of a textbox in selenium
Use clear() method.
driver.findElement(By.xpath("xpath of
box")).clear();
12) What is a Framework?
A framework is set of automation guidelines which help in
Maintaining consistency of Testing, Improves test
structuring, Minimum usage of code, Less Maintenance of code, Improve
re-usability, Non Technical testers can be involved in code, Training period of
using the tool can be reduced, Involves Data wherever appropriate.
There are five types of framework used in software
automation testing:
1-Data Driven Automation Framework
2-Method Driven Automation Framework
3-Modular Automation Framework
4-Keyword Driven Automation Framework
5-Hybrid Automation Framework , its basically combination of
different frameworks. (1+2+3).
13)
What is Datadriven & Keyword Driven framework?
Datadriven framework- In this Framework , while Test case
logic resides in Test Scripts, the Test Data is separated and kept outside the
Test Scripts.Test Data is read from the external files (Excel File) and are
loaded into the variables inside the Test Script. Variables are used both for
Input values and for Verification values.
Keyword Driven framework- The Keyword-Driven or Table-Driven
framework requires the development of data tables and keywords, independent of
the test automation tool used to execute them . Tests can be designed with or
without the Application. In a keyword-driven test, the functionality of the
application-under-test is documented in a table as well as in step-by-step
instructions for each test.
14)
What are different components of your framework?
Library- Assertion, ConfigLibrary, GenericLibrary,
ProjectSpecificLibrary, Modules.
Drivers folder, Jars folder, excel file.
13)
How to get the title of the page ?
Use getTitle() method.
Syntax- driver.getTitle();
14)
FirefoxDriver is class or an interface and from where is it inherited ?
FirefoxDriver is a class. It implements all the methods of
WebDriver interface.
15)
What is the difference b/w close() and quit()?
close() – it will close the browser where the control is.
quit() – it will close all the browsers opened by WebDriver.
16)
There is a scenario whenever “Assert.assertEquals()” function fails
automatically it has to take screenshot. How can you achieve this?
By using EventFiringWebDriver.
Syntax-EventFiringWebDriver eDriver=new
EventFiringWebDriver(driver);
File srcFile = eDriver.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(srcFile, new File(imgPath));
17) What are the benefits of using
TestNG?
a) TestNG allows us to execute of test cases based on group.
b) In TestNG Annotations are easy to understand.
c) Parallel execution of Selenium test cases is possible in
TestNG.
d) Three kinds of report generated
e) Order of execution can be changed
f) Failed test cases can be executed
g) Without having main function we can execute the test
method.
h) An xml file can be generated to execute the entire test suite.
In that xml file we can rearrange our
execution order and we can also skip the execution of particular test case.
18)
What are the browsers supported by Selenium IDE?
Mozilla FireFox only. Its an Firefox add on.
19)
How do you identify the Xpath of element on your browser?
To find the xpath, we use Firebug addons on firefox browser
and to identify the xpath written we use Firepath addons.
20)
Which one is better xpath or CSS?
xpath.
21)
How will you handle dynamic elements?
By writing relative xpath.
22) what are the different assertions
or check points used in your script?
The common types of validations are:
a) Is the page title as expected,
b) Validations against an element on the page,
c) Does text exist on the page,
d) Does a javascript call return an expected value.
method used for validation – Assert.assertEquals();
23)
Can we run group of test cases using TestNG?
Yes.
24)
What is object repository?
A repository allows a tester to store all the objects that
will be used in the scripts in one or more centralized locations rather than
letting them be scattered all over the test scripts.
Related Testing Topics:
a. Testing Tools
b. Basics of Java for Selenium
No comments:
Post a Comment