A Interview Questions- selenium
Automation testing Interview Questions
=================================
1. What is Automation
Testing?
Automation testing is the process of testing the software
using an automation tool to find the defects. In this process, executing the
test scripts and generating the results are performed automatically by using
automation tool. Some most popular tools do automation testing are HP QTP/UFT,
SELENIUM Webdriver, etc.,
2. What are the
benefits of automation testing?
·
Saves time and money .Automation testing is
faster in execution.
·
Reusability code, create one time and execute
multiple times with less or no maintenance.
·
Easy reporting .It generates automatic reports
after the test execution.
·
Easy for compatibility testing .It enables
parallel execution in the combination of different OS and browser environments.
·
Low cost maintenance. It is cheaper compared to
manual testing in a long run.
·
Automated testing is more reliable
·
Automated testing is more powerful and
versatile.
·
It is mostly used for regression testing.
Support execution of repeated test cases.
·
Minimal manual interventions. test scripts can
be run unattended.
·
Maximum coverage. It helps to increase test
coverage.
3. What types of test
you have attended?
Our main focus is to automat test cases to do regression
testing. Smoke Testing and sanity testing .Sometimes based on the projects and
the test time estimation, we do focus on END to END testing.
4. How many test cases
you have attended per day?
It depends on Test case scenario complexity and length. I
did automate 2-5 test scenarios per day when the complexity is limited.
Sometimes, just 1 or fewer test scenarios in a day when the complexity is high.
5. What is Framework?
A Frame work defines set of rules or best practices which
can follow in a Systematic way to achieve the desired results. There are
different types automation frameworks
and the most common ones are:
·
Data driven Testing Framework.
·
Keyword driven Testing framework
·
Hybrid Testing Frame work.
6. Have you created
any Framework?
If you are a beginner: No, I did not get a chance to create
a frame work. I have used the framework which is already available.
I your are experience tester: Yes, I have created a
framework. Or I have involved in the creation of framework.
7. Can you explain
the framework which you have used in selenium project?
-Note need to see other link Page abject model.
8. Why do you prefer
selenium Automation tool?
·
Free and Open source.
·
Have large user base and helping communities.
·
Cross browser capability.
·
Platform compatibility.
·
Multiple programming language support.
9. What is selenium?
Selenium is an Open Source (free) automated testing suite to
test web applications.It supports different platforms and browsers. It has
gained a lot of popularity in terms of web based automated testing and giving a great competitions to the
famous commercial tool HP QTP AKA HP UFT(Unified functional testing).
Selenium is a set of different software tools . Each tool
has a different approach in supporting web based automation testing.
It has four components testing namely.
i.
Selenium IDÉ
(Integrated Development Environment)
ii.
Selenium RC(Remote control)
iii.
Selenium Web Driver.
iv.
Selenium Grid.
10. What is selenium
IDE?
Selenium IDE is a Firefox plug-in. It is the simplest framework in the selenium
suite. It allows to record and playback the scripts. Even though we can create
scripts using Selenium IDE . We need to use Selenium RC or Selenium Web Drive
to write more advanced and robust test cases.
11. What is selenese?
Selenese is the
language which is used to write test scripts in selenium IDE.
12. Which is the only
browser that supports Selenium IDE to be used?
Firefox.
13. What is Selenium
RC?
Selenium RC AKA Selenium 1.
Selenium RC was the main Selenium project for a long time before the
webDriver merge brought up selenium 2. Selenium 1 is still actively supported
(in maintenance mode). It relies on JavaScript for automation. It Supports Java,
JavaScript, Ruby, PHP, Python, perl, Ruby.
14. What is selenium
WebDriver?
Selenium WebDriver AKA Selenium2 is a browser automation
framework that accepts commands and sends them to a browser. It is implemented
through a browser-specific driver. It controls the browser by directly
communicating with it. Selenium Web Driver Supports Java,C#,
PHP,Python,Perl,Ruby.
15. What is selenium
Grid?
Selenium Grid is a tool used together with Selenium RC to
run test on different machines against different browsers in parallel. That is,
running multiple tests at the same time against different machines running
different browsers and Operating systems.
In Simple word sit is used to distribute your test execution
on multiple platforms and Environment concurrently.
16. When do you use
Selenium Grid?
Selenium Grid can be used to execute same or different test scripts
on multiple platforms and browsers concurrently
so as to achieve distributed test execution.
17. What are the
advantages of Selenium Grid?
It allows running test case in parallel thereby saving test
execution time.
It allows multi-Browser testing.
It allows us to execute test cases on Multi-Platform
18. What is a Hub in
Selenium Grid?
A hub is a server or a central point that controls the test
execution on different machines.
19. What is a node in
Selenium Grid?
Node is a machine which is attached to the hub. There can be
multiple nodes in Selenium Grid.
20. What are the
types of Web Driver APIs AVAILABLE IN Selenium?
·
Firefox Driver.
·
Gecko Driver.
·
Internet Explorer Driver.
·
Chrome Drive.
·
HTMLUNIT
Driver.
·
Opera Driver.
·
Safari Diver.
·
Android Driver.
·
IPhone
Driver.
·
EventFiringWebDriver
21. Which Web Driver
Implementation claims to be the fastest?
The Fastest implementation of WebDriver Is the
HTMLUnitDriver. It is because the
HTMLUnitDriver does execute tests in the browser.
22. What are the programming language supported by Selenium
WebDriver?
·
Java
·
C#
·
Python
·
RUBY
·
Perl
·
PHP
23. What are the Operating systems supported by
Selenium WebDriver?
·
Windows
·
Linux
·
Apple
24. What are the Open
Source Frameworks Supported by Selenium WebDriver?
·
JUnit
·
Testng
·
Cucumber
·
JBHEAVE
25. What are the
Locators Available in Selenium?
·
ID
·
ClassName
·
Name
·
TagName
·
LinkText
·
PartialLinkText
·
Xpath
·
CSS Selector.
26. What is XPath?
XPath is used to locate
the elements Using XPath, we could navigate through elements and attributes in an XML
documents to locate web elements
such as
textbox,button,Checkbox,Image etc., in a web page.
27. What is the
difference between “/” and “//”?
Single slash “/” – Single slash is used to create XPath with
absolute path i.e the XPath would be created to start selection from the document node/start node.
Double slash”//”- Double slash is used to create XPath i.e
the XPath would be created to start selection from anywhere within the
document.
28. What is the
difference between Absolute Path and Relative Path?
Absolute XPath starts from the root node and ends with
desired descendent element node. It starts with top HTML Node and ends input
node. It starts with a single word slash(/) as shown as below.
/html/ body/div[3]/div[1]/form/table/tbody/tr[1]/td/input
Relative XPath starts from any node between the HTML page to
the current elements node [last node of the element). It starts with a single
forward slash (//) as shown below.
//input [@id=’email’]
29. What is the
difference between Assert and Verify in Selenium?
Assert: In simple
words , 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 willnotbe
executed.
Verify: In Simple words , there won’t be
any halt in the test execution
even though the verify condition is true or false.
For detailed post check the below link:
Assert Vs. Verify.
30. What are Soft
Assert and Hard Assert in Selenium?
Soft Assert: Soft
Assert collects error during @ Test Soft Assert
does not throw an exception when an assert fails and would continue with the next
step after the assert statement.
Hard Assert: Hard
Assert throws an Assert Exception immediately when an assert statement fails
and Test suite continues with next @Test
Detailed post:
Soft Assert
31. What are the
verification points available in selenium?
In Selenium IDE, we use Selenese Verify and Assert Commands
as verification points
In Selenium Web Driver , there is no built-in features
for verification points . It totally depends on our coding styles. Some
of the verification points are.
To check for page title
To check for certain text
To check for certain elements (text box, button, drop down
,etc.,)
32. How to launch
a browser using Selenium WebDriver?
WebDriver is an interface. We create Object of a WebDriver
Interface.
To Launch Firefox driver: WebDriver driver=new
FirefoxDriver();
To Launch Chrome Driver: WebDriver driver= new
ChromeDriver();
To Launch Internet Explorer : WebDriver driver= new
InternetExplorerDriver();
33. Is the FirefoxDriver a Class or an Interface?
FirefoxDriver is a Java Class, and it implements the
WebDriver Interface.
34.What is the Super
Interface of WebDriver?
SearchContext.
35. Explain the line of
code Webdriver driver= new FirefoxDriver();?
WebDriver driver= new FirefoxDriver();
“WebDriver” is an interface and we are creating an object reference
type driver instantiating on object
of FirefoxDriver class.
36.Why do we create a reference variable ‘driver’ of
type WebDriver
WebDriver driver =
new FirefoxDriver();(Note important: this concept is Dynamic polymorphism)
Instead of writing
Firefox Driver = new FirefoxDriver();
What was the purpose of doing this way?
If we create a
reference variable driver of type
WebDriver then we could use the
same driver variable to work with any browsers of our choice such as IEDriver,SafariDriver etc.,
37. What are the different exceptions you have faced in Selenium WebDriver?
·
WebDriverException
·
TimeOutException
·
NoAlertPresentException
·
NoSuchWindowException
·
NoSuchElementException
·
StaleElementReferenceException
·
IllegalStateException
38. How to login into
Any Site it it is showing Authentication Pop-Up for
Username and Password?
To do this we pass Username and Password using the URL
39. What are the types
of waits available in selenium WebDriver?
In Selenium we could see three type of waits such as
“Implicit waits, Explicit Waits and fluent wait
and Pageload wait waits and Thread .Seep().(NOTE :Please go through
videos and learn what these waits are it is important).
·
Implicit
·
Explicit
·
Fluent
·
Pageload
·
Thread.sleep()—Static wait
40. What is Implicit
wait in Selenium WebDriver?
Implicit wait tell to the
WebDriver to wait for a certain
amount of time before it
throws an exception. Once we set
the time, WebDriver will wait for the element based on the time we set before
it throws an exception The default setting is 0. We need to set some wait time
to make WebDriver wait for the required time.
41. What is Web
Driver or Explicit wait in Selnium
WebDriver?
WebDriver wait is applied on a certain element with defined
exception condition and time. This wait is only applied to the specified element.
This wait can also throw an exception when an element is not found.
42. What is fluent
wait in selenium webdriver?
Fluent wait can define
the maximum amount of time to wait
for a specific condition and frequency
with which to check the condition before
throwing an
“ElementNotVisibleException” exception.
43. How to input text in the box
using Selenium WebDriver?
By using SendKeys()
method
WebDriver driver = new FirefoxDriver();
Driver.get(http://www.gmail.com”);
Driver.findElement(By.xpath(“xpath”)).sendKeys(“Software
Testing material Website”);
44.How to input text in
the text box without calling the
sendKeys()?
//To initialize JS object
JavascriptExecutor JS=(JavascriptExecutor)driver;
//To ener Username
JS.executeScript(“document.getElementById(‘User’).value=’Siftwaretesting
material’ “);
// To enter password
JS.executeScript(“document.getElementById(‘Password’).value=’tester’
“);
45.How to clear the text in the text box using
Selenium Webdriver?
By Using Clear() method.
WebDriver driver= new FirefoxDriver();
Driver.get(http://www.gmail.com);
Driver.findElement(By.xpath(“xpath_of_element1”)).sendKeys(“Software
Testing materials”);
driver.findElement(By.xpath(“xpath_of_element1”)).clear();
46. How to get text
of a web element?
By using getText() method
47. How to get an
attribute value using Selenium WebDriver?
By using getAttribute(value);
48. How to click on a Hyperlink Using Selelnium WebDriver?
We use Click()method
in selenium to click on the hyperlink
driver.findElement(By.linkText(“Software Testing
Material”);).click();
49. How to submit a
form using Selenium WebDriver?
We use Submit () method on element to submit a form
driver.findElement(By.id(“form_1”).submit();
Alternatively, you can use click method on the element which does
form submission
50. How to Press Enter
Key on text box in Selenium Webdriver?
To press ENTER key using selenium webdriver. We need to use
selenium Enum Keys which its costant
ENTER.
driver.findElement(BY.xpath(“xpath”)).sendKeys(Keys.ENTER);
51. How to pause a test
execution for 5 Seconds at a specific point?
By using java.lang.Thread.sleep(long milliseconds)
method we could pause the execution
for a specific time.To pause 5
seconds , we need to pass parameter as
5000(5 seconds)
Thread.sleep(5000
52. In Selenium server needed to run Selenium WebDriver
Scripts?
When we are distributing our selenium Webdriver scripts to
execute using selenium Grid, we need to use selenium script.
53. What happens if I
run this command?
driver.get(www.softwaretestingmaterial.com);
An exception is thrown. We need to pass HTTP protocol within
driver.get()method.
Driver.get(http://www.sofwaretestingmaterial.com);
54. What is the Alternate
to driver.get() method to open an URL
using selenium WebDriver?
Alternate method to driver.get(“url”) method is driver.navigate.to(“url”);
55. What is the difference
between driver.get (“url”) and driver.navigate.to (“url”)?
Driver.get(): To Open
an URL and it will wait till the
whole page gets loaded
Driver.navigate.to():
To navigate to an URL and it will not wait till the whole page is loaded
56. Can I Navigate
back and forth in a browser
in SeleniumWebdriver?
We use navigate Interface to do navigate back and forth in a
browser. It has methods to move back, forward as well as to refresh the page.
driver.navigate().forward() :- to navigate to next web page
with refrence to the browsers history.
driver.navigate().back:- Takesback t the previous web page with refrence to thebrowser history
driver.navigate().refresh:- To refresh the current web page
thereby reloading all the web elements.
Driver.navigate().to(”url”):-to launch a new web browser and navigate to the specified URL.
57. What are the
different type of navigation commands?
Refer above question (Can I navigate back and forth in a
browser).
58. How to fetch
current page URL IN SELENIUM?
To fetch current page url, we use getCurrentURL();
Driver.getCurrentURL
59. How can we maximize
browser window in selenium?
To maximize browser window in selenium we use Maximize () method.
This method maximizes the current window if it is not already maximized.
Driver.manage().window().maximize();
60. How to delete
cookies in selenium?
To delete cookies we use deleteAllCookies()method.
61.What are the ways to refresh a browser using Selenium Web Driver?
There are multiple ways to refresh a page in selenium
·
Using driver.navigate().refresh() command
as mentioned in the question 45
·
Usinf driver.get(“url” on the current url or
using driver.getCurrentUrl()
·
Using driver.navigate().to("url”) on the
current url or driver.navigate().to(driver.getCurrentUrl());
·
Using SendKeys(Keys.F5) on the text box on the web page.
62.What is the
difference between driver.getWindowHandle() and driver.getWindowHandles() in
selenium Webdriver?
driver.getWindowHandle():-It returns the handle of the current page(a unique identifier)
driver.getWindoWindowHandles():- It returns a setoff
handles of all the pagesavailable.
63. What is the
difference between driver.close()
and driver.quit() methods?
Purpose of these two methods is almost same .Both allow us to
close a browser but still, there is a difference.
Driver.close():-To close current WebDriver instance
Driver.quite():- To closeall theopened webdriver instances.
64.What is difference
between driver.findElement() and driver.
findElements() commands?
The difference between driver.findElement and driver.findElements commands is
·
findElement() return a single WebElement(found
first) based on the locator passed as
parameter. Whereas findElements() returns a
list of WebElemnts, all satisfying the locator value passed.
·
Syntax of findElement
·
WebElement textbox=
driver.findElement(By.id(:textBoxLocator”));
·
Syntax of findElements()
·
List<webElement>
elements=elements.findElements(By.id(“value”));
·
Another difference between two is :-if no
element is found then findElement() thows
NoSuchElementException whereas findElements() returns a list of 0 elements.
65.How to find
whether an element is displayed on the
web page?
WebDriver facilitates the user with the following methods to
check the visibility of the web elements. These Web elements can
be buttons, drop boxes checkboxes, -radio buttons ,lables etc.
1 is displayed
2Boolean elepresent
=driver.findElement(By.xpath(“xpath”)).isDisplayed();
3 is selected
4 boolean
eleseected=diver.findElement((By.xpath(“xpath”)).isSelected(0;
5 isenabled
6 boolean
eleEnabled=driver.findElement(By.xpath”)).isEnabled();
isDisplayed:-
·
It is a method
used to verify the presence of a web element within the web page.The method return true
value if the specified web element is present on the web page and a ‘false “ value if the web element is not present on the web page.
·
isDisplayes():-it is capable to check for the presence of all kinds of web elements
available.
·
isEnabled():-it is the method used to verify the web element is enabled or disabled
with in the web page.
·
IsEnabled is primarlly used with buttons.
·
IsSeleleted();-It is the method to verify if the
web element is selected or not
·
IsSelectedmethod is is predominantly used with
radio button , drop down and check boxes.
66.How to select a value
in a dropdown?
By using select class
WebElement mySelelctElement=driver.findElement(By.name(“dropdown”));
Select dropdown =new
Select(mySelectElement);
Dropdown.selectByVisibleText(Text);
Dropdown.selectByIndex(Index);
Dropdown.selectByValue(value);
67. How to capture a
screenshort in selenium Web driver?
By using TakeScreenshort Interface.
Click on below links to see posts related to the normal way
of capturing a screen short and capturing a screen short using aShort utility
Capture screenshort using selenium WebDriver--link
FullPage Screenshort using
aShortutility--link
Failed Teste cases screenshorts.—link
68.How to Mouse Over
on a web element using WebDriver
By Using Action class
webElement ele=driver.findElement(By.xpath(“xpath”));
//Create object ‘actoin’ of an Action Class
Actions action=newActions(driver);
//Mouse over on an
element
Action.moveToElement (ele).perform();
69.How can we handle
web based pop up?
To handle alerts
popup we need to do switch to the alter
window and call Selenium
WebDriver Alert API methods
70.How can we handle
Window bases pop-ups?
Selenium does not support Window based applications. It isan
automation testing tool which supports only web based application testing. We
could handle window based pop-ups in selenium using some third party tool such as
AutoIT, Robot classetc.,
71. How to handle
hidden elements in Selenium WebDriver?
It is one of the most important selenium interview questions.
We can handle hidden elements by using javascript Executor.
(JavascriptExecutor(driver)).executescript(“document
.getElementsByClassName(ElementLocator).Click();”);
72. How can you find Broken
Links in a page using Selenium WebDriver?
See my video its concept of 30 minutes.
73. How to find more
than one web element in the list?
To store the list
List <WebElement> eleList=driver.findElements(By.xpath(“xpath”));
//To fetch the size of the list
Int
ListSize=eleLise.size();
//for loop
For(int i=0;i<listsize;i++)
{
//Clicking on each link
Links.get(i).click();
//navigate back to the preivious pae the stores the links
Driver.navgate().back();
}
74. How to read a
JavaScript variable in Selenium
WebDriver?
By using JavaScript Executor.
//To initialize js object
JavascriptExecutor JS=(JavascriptExecutor)webdriver;
//To get the site tittle
String title=(String)JS.executescript(“returndocument.title”);
System.out.println(‘title of the webpage:”+title);
75. How to read test data from excels?
Test data can be efficiently be read from excel using JXL OR POI API. POI API has many
advantages than JXL.
76. It is possible to
automate the captcha using selenium?
No, it is not possible to automate captcha and bar code
reader.
77.List some
scenarios which we cannot automate using
selenium WebDriver?
1. Bitmap comparison it is not possible using Selenium
WebDriver.
2. Automating Captcha it not possible using selenium
webdriver.
3. We cannot read barcode
using selenium webdriver.
4. Windows OS based Popups.
5. Third party calendars/elements
6. Image
7. World/Pdf
78.What is Object
Repository in selenium WebDriver?
Object Repository is used to store element locator values in
a centralized location
instead of hard coding them within the scripts. We do create a property file (.Properties) to
store all the elements locators and these property files act as an object
repository in selenium Web Driver.
79. How can you use
the Recovery Scenario in Selenium WebDriver?
By using”Try Catch Block” within the selenium WebDriver Java tests.
Try{
Driver.get(“www.xyz.com”);
}catch(Exception e){
System.out.println(e.getMessage());
}
80. How to upload
afile in selenium webdriver?
There are two cases which are majorly used to
upload a file in selenium webdriver.
Such as usingSendKeysmethod
and using AutoIT script.
Example: SendKeys(c:\\test\\bindu.jpg); condition is that
browser Button type should be file
81. Hot to download a file in selenium webdriber?
By using AutoIt
script,we coul download a filein
selenium webdriver.
82. How to run Selenium WebDriver Test from the command line?
Run Java Program using
Command Prompt
Example class A{
}
cd c
c:javac A.java—here code complies
c:java A.java-here code executes by interpretor.
Run TestNG using Command Prompt
Java.org.testng.TestNG
C:\Users\Desktop\Workspace\testing\testig.xml
83.How to switch
between frames in selenium?
By using the following code we could switch between frames.
Driver.switchTo.frame(here we can pass id or name or index);
84. How to connect a
Database in selenium?
As we all know Selenium WebDriver is a tool to automate User
Interface. We could only interact with browser using selenium web driver
We use JDBC driver to connect the database in selenium(While
using Java Programming language)
85.How to Resize
browser window using selenium web driver?
To resize the browser
window to particular dimensions , we use ‘Dimension’ class to resize the
browser window
Example:
//Create object of
Dimension class
Dimension d =new Dimension(480,620);
//Resize the current window
to the given dimensions
Driver.manage().window().setSize(d);
86. How to Scroll Web Page
Down or Up Using Selenium WebDriver?
JavaScript scrollBy() method scrolls the document
by the specified number or
pixels.
87.How to perform
Right click action (Context click) in selenium webdriver?
We use Action class in selenium webdriver to do Right-Click
(Context click) actions.
Example:
Action.contextClick(rightClickElement).build().perform();
88.How to perform double click action in selenium webdriver?
We use Action class to do Double click action in selenium
89.How to perform
Drag and drop actions in Selenium webdriver?
We use action class to Drag and Drop Action
Example:
Action action=new Action(driver);
Action.clickAndHold(driver.findElement(By.xpath(“//*[@id=’draggable’]”)))
.moveToElement(driver.findElement(Bt.xpath(“//*[id@=’droppable’]”)))
.release()
.build()
.perform();
90. How to Highlight
Element using Selenium WebDriver?
By using JavascriptExecutor interface,we could
highlight the specified element
***Important concept javascriptExecutor please go through
that concept in my video.
-------------------------------------------------------------
Ø
Challenges
faced using Selenium Automation testing, and how to solve them
Selenium at times fails to function correctly in a dynamic
event or change take place duting the test cycle. A few common problems faced
are listed below, along with how to mitigate them with selenium automation
1. Image or Text overlapping issues
2. No facility to deal with Captcha, bar code.
3. Does not support any non web based like(Win32,Java
Applet, Java Swing,.Net client server etc) applications.
4. When you compare selenium with QTP ,SILK TEST, Test
Partner and RFT, there are many challenges in terms of maintainability of test
cases.
5. Since selenium is a freeware tool, there is no direct
support if one is n trouble with the support of the application.
6. Bitmap comparisons is not supported by selenium.
7. Any reporting related capabilities, you need to depend on
third partytools.
8. You need to learn any one of native language
like(.Net,Java,Perl,Python,PHP,RUBY) to work effectively.
9. Difficult to identify dynamic objects.
10. Working with frames.
11 . Selenium test playback is slow.
12. JavaScript sandbox,Flash,Applets,Silverlights and HTML’S
Canvas all present problems n selenium.
13. Dealing with Popup
windows: Selenium can sometimes fail to record common popups in web apps.
To handle any kind of alert popup , you
can apply a get Alert Function. Before actually running the script , you must
import a package that can generate a WebDriver script for handling
alerts. The efficient interface brings with it the following commands: void dismiss(), void
accept(),getText() void sendKeys(string stringTosend).The first two basically
click on the “Cancel” and “OK” BUTTONS respectively
on a popup windows .
14. Timeout resulting
from synchronization problem: One should ideally use
selenium.IsElementPresent(locator) to verify that the object is in a loop
with Thread.sleep()
15.Testing Flash app: To automate flash apps with selenium, one can use Flex Monkium.The application source code
must be compiled with the swc
files generated by Flex Monkium. Then the app and the selenium
IDE are connected, and the tests can be recorded
16. Unexpected error
launching Internet Explorer: Browser zoom level should be set to
100% by default for the IE
browser to overcome this error.
17. Protected Mode: must
be set to the same value error
occurs when trying to run
selenium WebDriver on a
fresh Windowsmachine.This issue can be
fixed by using capabilities as below
when launching IE.
18. Cross browser tesing issues.
19.Ajax Compenents.
------------------------------------------------------------------------------------------------------------------------------------------
TestNG
1. What is TestNG?
TestNG is a testing framework designed to simply a broad of
testing needs, from unit testing to integrate
testing.
2. What are the
advantages of TestNG?
·
TestNG provides parallel execution test method.
·
It allows to define dependency of one test
method over other method.
·
It allows to assign priority to Test methods.
·
It allows grouping of test methods
in to test groups
·
It has support of parameterzing test cases using @parameter annotation
·
It allows data driven testing using @Data provider annotation
·
It has different assertions that helps
in checking the expected and actual results
·
Detailed HTML reports.
·
Testing Listeners
3. What are the Annotations
available in TestNG?
@BeforeTest
@AfterTest
@BeforeClass
@AfterClass
@BeforeMethod
@AfterMethod
@BeforeSuite
@BeforeGroups
@AfterGroups
@Test
4. Can you arrange the
below testing.xml tags parent to child?
<test>
<suite>
<class>
<method>
<classes>
The correct order of the TestNG tags are as follows:
<suite>
<Test>
<classes>
<class>
5. How to create and
run testing.xml?
In TestingNG
framework, we need to create testing.xml file to create and handle
multiple test classes. We do configure our test run, set test dependency,
include or exclude any test, method, class or package and set priority etc in the XML file.
6. What is the
important of testing .xml file?
In a selenium TestNG project , we use testing.xml file to
configure the complete test suite in a
single file. Some the features are as
follow:
·
Testing.xml file allows to include or
exclude the execution of test methods and test groups
·
It allows to pass parameters
to the test cases
·
Allows to add group dependencies
·
Allows to add priorities to the test cases
·
Allows to configure parallel execution of test
cases
·
Allows to parameterized test cases.
7. How to pass parameter
through testing.xml file
to a test case?
We could define the parameters in the testing.xml file and then
reference those parameters in the source file.
@Test
@parameters(“browsers”)
Public void parametizedtest(String browser){
If(browser.equals(“firefix”){
s.o.p(”open firefox browser)
if(browser.equals(“chrome”){
s.o.p(“open chrome browser)
<parameter name=”browser” value=”firefox”/>
Here , name attribute
represents the parameter
name and value represents
the value of that parameter.
8.What is TestNG assert
and list out common TestNG
Assertions?
TestNG Asserts help us to verify the condition of the test
in the middle of the test run.
Based on the TestNG Assertions, we will
consider a successful test only if it is
completed the test run
without throwing any exceptions.
Some of the common assertions supported by TestNG are.
·
assertEqual(String actual, String Expected)
·
assertEqual(Stringactual,String expected, String
Message)
·
assertEqual(Boolean actual, Boolean expected)
·
AssertTrue(condition)
·
assertTrue(condition, message)
·
assertFalse(condtion)
·
assertFalse(condition, message)
9. What is soft
assert in TestNG?
Soft Assert collect error 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
AssertAll() method as a last statement
in the @Test and test suite again
continue with the next @Test as it is.
10. What is hard
assert in TestNG?
Hard Assert throws an AssertException immediately when an
assert statement fails and test uite continues
with the next@Test.
11. What is exception
test in TestNG?
TestNG given an option for tracing the Exception handing of the code. You can verify whether a code throws
the expected exception or not. The expected exception to validate while
running the test case is mentioned
using the expectedFunction attribute
value along with @ Test annotation.
12. How to set test case priority in TestNG?
We use priority attribute to the Test@ annotations. In cas priority
is not set then the test
scripts execute in
alphabetical order.
//TestNG interview question.
Package TestNG;
Import org.testng.annotations.*;
Public class priorityTestCase{
@Test(priority=0)
Public void testcase1(){
s.o.p(“Test case1”);
}
@Test(priority=1)
Public void testcase2(){
s.o.p(“Test case2”);
}
}
Output :
Testcase1
Test case2
13. What is
parameterized testing in TestNG?
Parameterized tests allows developers to run the same test over
and over again using different values.
·
Using testing.xml
·
Using data providers
14. How can we create
data driven framework using TestNG?
By using @DataProvider annotation, we can create
a data Driven Framework.
@DataProvider(name=’getdata’)
Public Object[] [] getData(){
Object[][]data=new object[rwocount][colcount];
Object[][]data=new Object[2][2];
Data[0][0]=”FirstUid”;
Data[0][1]=”FirstPWD”;
DATA[1][0]=”SecodUid”;
Data[1][1]-“SecondPWD”;
Return data;
15. How to run a
group of test cases using TestNG?(not important)
TestNG allows you to perform
sophisticated groupings of test methods.
Not only can you declare that methods
belongs to groups, but you can
also specify groups that contain other
groups. Then TestNG can be invoked and asked to include a certain setoff groups
while executing another set. This gives
you maximum flexibility in how
you partition your tests and does not
require you to recompile anything if you want to run two different
sets of tests back to back
16.How to create Group of groups in TestNG?
Groups can also include in other groups. These groups are
called MetaGroups. For example, You might want to define a group al that
includes smoketest and functionaltest. Let’s modify out testing .xml file as follows:
<groups>
<define name=”all”>
<include name=”smoke test”/>
<include name=”functional test”/>
</define>
<run>
<include name =”all”/>
</run>
</groups>
17.How to run test cases in parallel using TestNG?
We can use ‘parallel’ attribute in testing.xml to accomplish parallel test
execution in TestNG.
The parallel attribute of suite tag can accept
four values:
Tests----All the test cases inside <test> tag of
testing.xml will run parallel.
Classes—Allthe test cases inside a java class will run
parallel
Methods---All the methods with @Test annotation will execute parallel
Instance---Test cases in same instance will execute parallel
but two methods of two different
instances will run in different thread.
<suite
name=”sofwaretestingmaterial”parallel=’methods“>
18. How to exclude a
particular test method from a test case execution?
By
adding Exclude tag in the testing.xml
<classes>
<class name=”TestCaseName”>
<methods>
<exclude name=’TestMethodNameToExclude”/>
</methods>
</class>
</classes>
19.How to exclude a
particular test group from a test case execution?
By adding the exclude tag in the testing.xml
<groups>
<run>
<exclude name=”TestGroupNameToExclude”/>
</run>
</groups>
20.How to disable a
test case in TestNG?
To
disable a test case we use a parameter enabled=false to the @Test annotation
@Test(enabled=false)
21.How to skip a
@Testmethod from execution in Test NG?
By using throw new SkipException()
Once SkipException() thrown, remaining part of that test
method will not be executed
and control will goes
directly to next test method execution.
22.How to ignore test
case in TestNG?
To ignore the test case
we use the parameter enabled =false
to the @Test annotations
@Test(enabled=false)
23.How TestNG allows
to state dependencies?
TestNG allows two ways to declare the dependencies
Using attributes dependsOnMethods in @Test annotation. And
using attributes dependsOnGroups in @Test annotations
24.What are the
different ways to produce reports for TestNG Actions?
TestNG offers two ways to produce reports
Listeners implements
the interface
org.testing.ITestListener and are notified in real time
of when a test stats, passes, fails etc.,
Reporters implement the interface org.testig.IReporter and
are notified when all the suites have been run by TestNG. The IReporter instance
receives a list of objects that describes the entire test run.
25.What is the use of
@Listenerannotation in TestNG?
TestNG LISTENERS are used to configure reports and
logging.One of the most widely used
listeners in TestNG is ITestListenerinteface. It has methods like onTestStart,
onTestSuccess, onTestFailure,onTestSkipped etc., We should implement this interface creating a listener
class of our own . Next we should
add the listeners annotations(@Listener) in the class which we created.
26.How to write regular expressios in testing.xml file to
search @TestMethods containing “Smoke”keyword.
Regular expressions to find @Test Methods containing
Keyword “smoke” is as mentioned
below.
<methods>
<include name=”.”*smoke.*”/>
</methods>
27.What is the time unit
we specify in test suites and test cases?
We specify the time unit in test suites and test cases is in milliseconds.
28.List out various
ways in which TestNG can be invoked?
·
Using Eclipse IDE
·
Using ant built tool
·
From the command line
·
Using Intelli’s IDEA
29.How to run TestNG using command prompt?
C:test
Java c://testing.jar test.java
30. What is the use
of @Test(invocationCount=x)
The invocationcount attribute tells how many times TestNG
shoul run a test method
@Test(invocationcount=10)
Public void testcase1(){
In this method testcase1 will ne invoked 10 times
31. what is the use
of @Test(threadpoolsize=x)?
The ThreadPoolSize attribute tells to form a thread pool to run thetest
method through multiplpe threads.
Note:This attribute is ignored
if invocationcount is not
specified
@Test(ThreadPoolSize=3,<code class =’plain’>invocationcount=</code><code
class=”value”>10</code>public void testcase1(){
In this example the
method testcase1 wii be invoked from
thee different methods
32.What does the test
timeout mean in TestNG?
The
maximum numberof millisecondsa test case should take.
@Test(ThreadPoolSize=3,invocationcount=10,timeout=10000)
Oublic void testcase1(){
In this example, the
method testcase will be invked ten times
from three different threads. Additionoally , a time out of ten seconds guarantees that none of the threads will blocj
on this thread forever.
33.What are @Factory
and @DataProvider annotations?
@Factory:A factory
will execute all the test ethods present
inside a test class using a separate
instance of the respective class with different setof data.
@DataProvider: Atest method that uses DataProvider will be executed the
specific methodsmultiple number of
times based on the data provide by the DataProvide. The Test methods will be excuting using
the same instance of the
test class to which
the test methods belongs.
================================================================================
Pros and Cons of selenium WebDriver.
--------------------------------------------------------------------------------------
1.
Open Source.
2.
Supports multiple languages Java c# .net python
perl ruby php javascript
3.
Supports all platforms/os Windows,MAC
OS,Linux,Unix
4.
Cross browser testing Chrome,Firefox,Safari,IE Opera
5.
Head less
browsers PhatomJS HTMLunitDriver Chrome HeadLess
6.
Can be
integrated with any open source unit testing framework TestNG Junit
7.
BDD
Frameworks Cucumber,JBehave,Serenity
8.
Light
Weight
9.
Availablein
the form of APIs
10.
Easily integrated with CI—CD process, Jenkins
11.
Can be executed on local machines as well
as Cloud/VM/Servers/BrowserStack
SauceLabs AWS Docker
12.
Customize WebDriver codebase—soure code will be
shared
13.
Wrappers:Appium,Protractor,Watir,Robot
Framework.
Cons:
====
1 .As it is Open Source , So no
direct Support
2.You need to learn programming—No
Srciptless or codeless automation
3. No Desktop app Automation
support
4.no report for test results
5. for any extra work:test case
designing,report,build,CI-CD
6. NO BAR CODE/NOCAPTCHA
Comments
Post a Comment