Selenim Interview Questions (AutoRecovered)
Selenim Interview Questions (AutoRecovered)
driver.get("http://demo.guru99.com/test/guru99home/");
//Different ways To maximize the window. This code may not work
with Selenium 3 jars. If script fails you can remove the line below
driver.manage().window().maximize(); OR
driver.manage().window().SetSize(dimesion); OR
System.setProperty(“webdriver.chrome.driver”, “C:\\chromediver.exe
location”);
chromeOptions chromeoptions = new ChromeOptions();
chromeOptions.addArguments(“—-start-maximized”);
WebDriver driver = new ChromeDriver(ChromeOptions);
hhtp://username:password@URL
driver.get("http://admin:[email protected]/test/guru99home/");
Xpath starts with // then html tag and add property then the name/class/id
After writing xpath, check whether its showing 1 0f 1 at the corner to use
Example 01: //input[@name=’username’] //If you’re using “@” then we have
to use =, if you’re using “contains” then use “,”
Example 02:
If no id/name/class is present then,
//input[@type=’submit’ and @value=’Login’] //[] attribute we
need to give inside, we can provide single or combination of multiple
attributes by using and operator
Example 03:
Xpath for links, If no property is present in the html tag like id/name/class/link, etc
//a[text()=’Winter’] //text() is a function so we cannot use ‘@’ here,
without contains
Example 04:
//button[contains(text),’sign up’]
Example 05:
Dropdown button having more than 1 class, and buttons having same property then xpath will
be included with parent type,
//div[@class=’dropdown’]//button[@type=’button’ and @class=’btn btn-
secondary dropdown-toggle’ and @id=’dropdownmenubutton1’] or
//button[@id=’dropdownmenubutton1’]
Example 06:
Xpath for checkbox in a table, if you’re using parent property in xpath use two colons “::”
It is the main component of selenium. Selenium webdriver has a collection of API’s (Class &
Interfaces) to automate the web application.
Selenium grid will distribute the automated tests across multiple machines.
Selenium grid used with testNG, can enable parallel execution of tests across multiple machines.
IN Selenium grid configuration, one machine is configured as Hub and other machines are
configured as Nodes. //*[@id="inPageSearchForm"]/div[2]/div/div/div[1]/div[4]/button
Automation tests are triggered for execution from Hub machine but the triggered test cases will
be executed in different node machines.
Node machines can have different platforms & browsers.
The total number of links in a page can be counted with the help of findElements() method.
To find no.of links = //a, it’ll show the count of total links …. //a means anchor tag to get all the links
Action.perform(); // build will create the action and perform method will complete the action
Actions class is an ability provided by Selenium for handling keyboard and mouse events. Action
class in derived from advanced user interactions API.
Actions.dragAndDrop(Source”From”, Target”To”).build().perform();
executescript() method executes the test script in the context of the currently selected window
or frame. The script in the method runs as an anonymous function. If the script has a return
statement, the following values are returned:
WebElement
List
String
Long
Boolean
driver.getWindowHandle() – It fetches the handle of the web page which is in focus. It gets the
address of the active browser and it has a return type of String.
driver.getWindowHandles(): It is used to get the address of all open browsers, and its return
data type is Set<String>.
webdriverManager.Chromedriver().setup();
} driver.quit();// This will close all the windows opened by the driver
iframe is often used to add content from other sources like an advertisement into a web page. The
iframe is defined with the <iframe> tag. HTML document embedded inside another HTML
document.
Suppose if there are 100 frames in page, we can switch to frame by using index.
driver.switchTo().frame(0);
driver.switchTo().frame(1);
Nested Frame – HTML document embedded inside another HTML document which is embedded
into another HTML. Switching from Outer frame to inner frame.
driver.switchTo().defaultContent(); // Switching back to the main window
driver.switchTo().frame(1);// Frame 2
driver.switchTo().frame(“ID or Name or webelement”);// Directly mention ID
or name inside frame.
driver.switchTo().defaultContent();
Right click action in Selenium web driver can be done using Actions class. Right Click operation is also
called Context Click in Selenium. Pre-defined method context click provided by Actions class is used
to perform right click operation. (Right Click Mouse Action)
Double click action in Selenium web driver can be done using Actions class. Actions class is a
predefined class in Selenium web driver used to perform multiple keyboard and mouse operations
such as Right Click, Drag and Drop, etc.
driver.get("http://demo.guru99.com/test/simple_context_menu.html");
driver.manage().window().maximize();
TestNG suite?
TestNG data provider? Watch video with example
How will you perform dropdown in selenium? Syntax and methods you need to explain
//we can use sendkeys also to select from drop down options
dropdown1.sendkeys(“dropdown option”);
Throw: Throw keyword is used to throw exception to the runtime to handle it.
Try/Catch: A @try block encloses code that can potentially throw an exception. A @catch()
block contains exception-handling logic for exceptions thrown in a @try block.
Finally Keyword always used with Try Catch block, Finally block will get executed after the
Try Catch block.
Finally: A @finally block contains code that must be executed whether an exception is
thrown or not:
The finally block is always executed, even if the try block or catch block contains a return
statement.
Finalize keyword used to perform the cleanup. Using garbagecollector().
Final keyword (f-small) used to define the constant value, value we cannot change/modify
the value of final variable. It also used to prevent inheritance.
The finalize() method in Java is called when an object is about to be garbage collected. The
finalize() method can be used to perform any necessary cleanup before the object is garbage
collected.
A server generates HTTP Status codes in response to the request submitted by the client to the
server. The first digit of the status-code is the response type, and the last two digits have
different interpretations associated with the status code.
1. It checks the version of the browser installed in your machine (e.g. Chrome, Firefox).
2. It checks the version of the driver (e.g. chromedriver, geckodriver). If unknown, it uses the
latest version of the driver.
3. Check if the driver is already present in our system. If yes, does nothing. If not, it downloads
and set the environmental path.
4. To use WebdriverManager in Maven project, we need to add dependency in pom.xml
WebDriverManager is an open source not part of Selenium WebDriver API.
Webdriver: System.setProperty("webdriver.chrome.driver",
"./Drivers/chromedriver.exe"); This will setup driver executable for a specific
browser based on the location that we have provided where we downloaded and placed
driver executable/s.
To automate web applications we need to download driver executables manually for required
browsers. Once driver executables are downloaded into local system then we need place them in a
specific path and set path for driver executables
1. We need to download driver executables manually and set path for the same.
2. As and when browser version is updated, we need to download driver executable/s that can be
matched with latest browser version.
3. We need to set exact path for driver executable/s else we get illegalStateException. [When we try
to launch browser without setting correct path for driver executable/s]
To rerun failed test runs automatically during the test run itself, we
implement IRetryAnalyzer interface provided by TestNG. By
overriding retry() method of the interface in your class, you can control
the number of attempts to rerun a failed test case. s
public class RetryAnalyzer implements IRetryAnalyzer {
package testngDemo;
import org.testng.Assert;
import org.testng.annotations.Test;
public class RerunFailedTest1 {
int counter;
@Test
public void test1() {
System.out.println("test run");
Assert.assertTrue(true);
}
@Test(retryAnalyzer = RetryAnalyzer.class)
public void failedtest1() {
Chrome driver, Firefox Driver, Internet Explorer driver, HTML Unit Driver, Android driver,
Iphone driver, Remote web driver.
First take the path of batch file, process batch = runtime.getruntime(“batch file path”);
To achieve that we can write java -classpath selenium-server- (standalone) Jar file (which we
get after download selenium) class name and hit enter
5. What are the different exceptions you face in selenium webdriver?
No alert present exception - it means that the test is too quick and is trying to find an alert
that has not yet been opened by the browser.
To handle or simply avoid this exception, use explicit or fluent wait in all events where an
alert is expected.
No such element exception - the exception occurs due to the use of incorrect element
locators in the findElement(By, by) method.
To handle this exception, use the wait command. Use Try/Catch to ensure that the program
flow is interrupted if the wait command doesn’t help.
Timeout exception - This exception is thrown if the command did not execute or complete
within wait time. As already mentioned, waits are used to avoid NoSuchElementException.
Element Not Visible Exception - When the WebDriver tries to find an element that is hidden
or invisible. To handle this exception, it is essential that the exact reason is identified, which
can be due to nested web elements or overlapping web elements.
In the first case, you have to locate and correct the specific element. In the second case, use
explicit wait.
When the element is present in the DOM (Document object model) but it is not visible on
the webpage. EX: Train ticket availability number refresh (Using ajax call), you can try to
access the element several times in a loop before finally throwing an exception.
Is a design pattern in selenium creating an object repository for storing all web UI element.
In Page Object Model, consider each web page of an application as a class file. Each class file
will contain only corresponding web page elements. Using these elements, testers can
perform operations on the website under test.
11. Which all file types can be used as a data source for different frameworks?
.csv – Is one of the property files that we can use in selenium framework
It is defined as an interface that modifies the behavior of the system. Listeners allow
customization of reports and logs.
4. Important: One parent window multiple child windows are opened to switch to
child windows (2) second one there is no title of the page?
13. Is it possible to navigate back & forth in webpage in a selenium? Which methos is used?
driver.manage.naviagte()
driver.manage.forward()
driver.manage.back()
driver.manage.navigate(“url”)
Take screenshot when an alert is open, It’ll give you exception “selenium.UnhandledAlertException”
Integration Testing
System Testing
End-to-End Testing
Regression Testing
Compatibility Testing
Performance Testing
UI/UX Testing
Asserts are validations or checkpoints for an application. Assertions state confidently that
application behaviour is working as expected. Asserts in Selenium validate the automated
test cases that help testers understand if tests have passed or failed.
Assert: Assert command checks whether the given condition is true or false. Let’s say we
assert whether the given element is present on the web page or not. If the condition is true
then the program control will execute the next test step but if the condition is false, the
execution would stop and no further test would be executed.
Verify: Verify command also checks whether the given condition is true or false. Irrespective
of the condition being true or false, the program execution doesn’t halts i.e. any failure
during verification would not stop the execution and all the test steps would be executed.
Waitfor: This command waits for some condition to become true. They will fail and halt the
test if the condition does not become true within the current timeout setting. Perhaps, they
will succeed immediately if the condition is already true.
Hard Assertions are ones in which test execution is aborted if the test does not meet the
assertion condition. The test case is marked as failed. In case of an assertion error, it will
throw the “java.lang.AssertionError” exception.
Different types of hard assertions with examples.
assertEquals() is a method that takes a minimum of 2 arguments and compares actual
results with expected results. If both match, the assertion is passed, and the test case is
marked as passed. assertEquals() can compare Strings, Integers, Doubles, and many more
variables.
assertNotEquals() is a method that does the opposite of the assertEquals() method. In this
case, the method compares the actual and expected result. But if the assertion condition is
met if the two are not identical. The test case is marked as passed if actual and expected
results are not the same.
assertTrue(): This Assertion verifies the Boolean value returned by the condition. If the
Boolean value is true, then the assertion passes the test case.
assertFalse(): This method works the opposite of assertTrue(). The Assertion verifies the
Boolean value returned by the condition. If the Boolean value is false, the assertion passes
the test case.
assertNull(): This method verifies if the expected output is null. If not, the value returned is
false.
assertNotNull(): This method works opposite to the assertNull() method. The assertion
condition is met when the method validates the expected output to be not null.
18. How will you handle mouse and keyboard actions using selenium?
Actions class is an ability provided by Selenium for handling keyboard and mouse events. Action
class in derived from advanced user interactions API.
WebDriverManager .ChromeDriver().setup();
21. Implicit Wait – Is a global wait which waits for all the webelements equally.
It’s a dynamic wait because its only wait if its required.
Driver.manage().timeouts.implicitlywait(30, Timeunits.seconds); //Default waiting time is 0
second
22. Explicit Wait – Used to wait for a specific web element to be displayed or loaded
23. Fluent wait – FluentWait instance defines the maximum amount of time to wait
for a condition, as well as the frequency with which to check the condition.
User also configure the wait to ignore specific types of exceptions while
waiting, such as NoSuchElementExceptions when searching for an element
on the page.
Is a design pattern in selenium creating an object repository for storing all web UI element.
In Page Object Model, consider each web page of an application as a class file. Each class file will
contain only corresponding web page elements
Object Repository means collection of all the web objects or web elements.
Page object model framework, same has been used for UI automation, API automation & Mobile
automation.
POM: As per page object model, we have maintained a class for every web page. Each web page has
a separate class and that class holds the functionality and members of the web page. Separate
classes for each individual test.
Packages: We have separate packages for pages and tests. All the web page related classes come
under the pages package and all the tests related classes come under the Tests package.
For ex: Login page and Payment page have separate classes to store element locators.
Property Files: This file (cofig.properties) stores the information that remains static throughout the
framework such as browser specific information, application url, development, testing url
screenshots path, security questions & answers, username, password, etc
Screenshots: Screenshots will be captured and stored in a separate folder and also the
screenshots of failed test cases will be added to the extent reports.
Maven: Using Maven to create a build, execution and dependency purpose. Integrating the
TestNG dependency in POM.xml file and running this POM.xml using Jenkins.
Version Control Tool: We use GIT as a repository to store our test scripts.
Jenkins – CI to trigger the build, we execute test cases on a daily basis based on the schedule. Test
results will be sent to peers using Jenkins.
Jenkins using POM.xml configuration, we integrated with devops. We’ll give the pom.xml file
location to devops.
Whenever the build is run it’ll automatically execute the test scripts.
Test Base Class: TestBase.java deals with all the common functions used by all the pages. This class is
responsible for loading the configurations from properties files, initializing the webdriver, implicy
waits, Extent reports.
From GIT use PULL to get the latest code from Master branch
Selenium Webdriver
TestNG report
GIT – Repository to maintain the code to push the code for check-in/check-out
Easy maintenance
Yes, using page factory @findby annotations above the particular element. Or We can directly use
the name/ID as a variable name in webdriver.
Get() is used to navigate to particular url (website) and wait for page load.
Navigate.to() is used to navigate to particular url (website) and does not wait to page load. It
maintains browser history or cookies to navigate back or forward.
A broken link, often called a dead link, is any link on a web page that no longer works because there
is an underlying issue with the link. When someone clicks on such a link, sometimes an error
message is displayed like a page not found. There may not be any error message at all. These are
essentially invalid HTTP requests and have 4xx and 5xx status code. Some common reasons for a
broken link on a webpage can be:
Test scripts developed based on the functionality, Worked on the functional scripts.
For the past the 6months I’m working on the management activities
Jenkins using Palm configuration, we integrated with devops. Whenever the build is run it’ll
automatically execute the test scripts.
RD Automation Channel
Page object model framework, same has been used for UI automation, API automation & Mobile
automation.
GIT – Eclipse ide used for GIT. Git add tat will mov to stage/index then GIT commit, this will be stored
in local repository, then GIT push will move to GIT cloud.
Fluent wait – default polling time is 0.5second. polling is nothing but frequency (3secs)
Full page A-shot – important
Checked Exception – Occur during the compile time itself (while writing program itself (Red line)).
Try Block – Code is written in this block which may give run time exception. Try block can have
multiple Catch block.
Catch Block – This is where the exceptions are handled. Catch block is immediately followed by Try
block. If there are no exceptions then the Catch block will not get executed.
Finally Block – Code will get executed even if the exception occurs or not. This block will contains
codes like closing connection of DB’s, buffers, streams, etc.
There is no finally block without a Try-Catch. A finally block must be associated with a try catch.
Finally block is not mandatory. If there’s any exception, then finally block will get executed after the
corresponding Catch block, else after Try block execution.
Finally block can also have exception. It can be handled using Try-Catch block.
Thread is dead
When System.exit() is called
When an unrecoverable exception happens in finally block.
First identify the pagination footer and get the size of it. If the size is greater than zero, then
we have pagination, else there’s no pagination.
We’re going to get the list of names from the web page table and add it to the list. So we
need two lists, one is string type and another one is webelement type List<String> nameList;
and List<WebElement> listOfNames;
Elements to be found,
Pagination footer
We need to click Next button, so next button
Table data
Logic going to use,
Going to find size of pagination, if zero perform logic to click next button and fetch
name else do nothing.
Find name cells and store in list of webelements
Create a for-each loop, iterate and store the names in list of string
Find next button/link
At the end of page, next button will be disabled so we are going to use that as our
indicator for end of the pagination.
webdriverManager.Chromedriver().setup();
List<WebElements> listofNames;
If(sizeofpagination>0)
Nameslist.add(name.gettext());
Nextclassname = nextbutton.getattribute(class);
Nextbutton.click();
} else {
Break; }
While(true);
When the child class extends from more than one superclass, it is known as multiple inheritance.
However, Java does not support multiple inheritance.
Array list:
To get index position use arraylist.indexof(“Value”);// Index of will show the first occurrence in
code
To get index last position use arraylist.lastindexof(“Value”);// LastIndex of will show the last
occurrence in code
To copy one collection to another collection in arraylist, arraylist.addall(which list to add); // .clear()
will clear the list
Listiterator.hasNext()
Listiterator.previous()
String is immutable and String buffer is mutable. Both are child of CharSequence interface.
Can able to create object using New Keyword only for String Buffer.
Final is an access modifier, finally is the block in Exception Handling and finalize is the
method of object class.
Final: Final keyword and access modifier used to define the constant value. We cannot modify the
value of final variable. It used to prevent inheritance. Final class/Final method
Finalize: Finalize (Garbage Collector) is the method in Java which is used to perform clean up
processing just before destroying any object. If there’s no object reference is available, immediately
garbage collector will be called or automatically it’ll be called. Get SYNTAX for this
Finally: Is a block, finally block will be executed after try catch block despite of exceptions. Any
exceptions is coming or not, Finally block will get executed.
Finally is the block in Java Exception Handling to execute the important code
whether the exception occurs or not.
Include Catch block (NullPointerException), after arithmetic exception, exception will not catch it
because of null pointer, even then Fianally block will get execute.
1. Definition final is the keyword and access finally is the block in Java Exception finalize is the method in Java which
modifier which is used to apply Handling to execute the important is used to perform clean up
restrictions on a class, method or code whether the exception occurs processing just before object is
variable. or not. garbage collected.
2. Applicable Final keyword is used with the Finally block is always related to finalize() method is used with the
to classes, methods and variables. the try and catch block in exception objects.
handling.
3. Functionality (1) Once declared, final variable (1) finally block runs the important finalize method performs the
becomes constant and cannot be code even if exception occurs or cleaning activities with respect to
modified. not. the object before its destruction.
(2) final method cannot be (2) finally block cleans up all the
overridden by sub class. resources used in try block
(3) final class cannot be inherited.
4. Execution Final method is executed only Finally block is executed as soon as finalize method is executed just
when we call it. the try-catch block is executed. before the object is destroyed.
Anything divide by 0 (3/0 or i/0) will give arithmetic exception in Java. 1/0 is infinite, Infinite cannot
be handled in Java.
Include Catch block (NullPointerException), after arithmetic exception, exception will not catch it
because of null pointer, even then Fianally block will get execute.
1) Abstract class can have abstract and non- Interface can have only abstract methods. Since Java 8, it can
abstract methods. have default and static methods also.
2) Abstract class doesn't support multiple inheritance. Interface supports multiple inheritance.
3) Abstract class can have final, non-final, static and non- Interface has only static and final variables.
static variables.
4) Abstract class can provide the implementation of Interface can't provide the implementation of abstract class.
interface.
5) The abstract keyword is used to declare abstract class. The interface keyword is used to declare interface.
6) An abstract class can extend another Java class and An interface can extend another Java interface only.
implement multiple Java interfaces.
7) An abstract class can be extended using keyword An interface can be implemented using keyword "implements".
"extends".
8) A Java abstract class can have class members like Members of a Java interface are public by default.
private, protected, etc.
9)Example: Example:
public abstract class Shape{ public interface Drawable{
public abstract void draw(); void draw();
} }
Throw keyword is used to throw an exception explicitly. It can throw only one exception at a
time. The throws keyword can be used to declare multiple exceptions, separated by a comma.
Throw and throws are the concepts of exception handling in Java where the throw keyword throws
the exception explicitly from a method or a block of code, whereas the throws keyword is used in
the signature of the method.
The throw keyword is used inside a The throws keyword is used in the function
function. It is used when it is required to signature. It is used when the function has some
1. Point of Usage throw an Exception logically. statements that can lead to exceptions.
Syntax of throw keyword includes the Syntax of throws keyword includes the class
instance of the Exception to be thrown. names of the Exceptions to be thrown. Syntax
Syntax wise throw keyword is followed by wise throws keyword is followed by exception
3. Syntax the instance variable. class names.
In Java, this is a reference variable that refers to the current object. This keyword refers to the
current object in a method or constructor.
Super and this keyword super() as well as this() keyword both are used to make constructor
calls. super() is used to call Base class's constructor(i.e, Parent's class) while this() is used to call the
current class's constructor.
Super keyword in Java is a reference variable which is used to refer immediate parent class object.
Whenever you create the instance of subclass, an instance of parent class is created implicitly which
is referred by super reference variable.
Javascript executor:
JavascriptExecutor executor = (JavascriptExecutor) driver;
//(JavascriptExecutor) this means type casting
Executor.executescript(“location.reload”);// or use
history.go(0);
In Java, a string is an object that represents a number of character values. Each letter in the string is
a separate character value that makes up the Java string object. Characters in Java are represented
by the char class.
Java String length(): The Java String length() method tells the length of the string. It returns count of
total number of characters present in the String.
Java String compareTo(): The Java String compareTo() method compares the given string with
current string.
Each of these build lifecycles is defined by a different list of build phases, wherein a build phase
represents a stage in the lifecycle.
For example, the default lifecycle comprises of the following phases (for a complete list of the
lifecycle phases, refer to the Lifecycle Reference):
validate - validate the project is correct and all necessary information is available
compile - compile the source code of the project
test - test the compiled source code using a suitable unit testing framework. These tests
should not require the code be packaged or deployed
package - take the compiled code and package it in its distributable format, such as a JAR.
verify - run any checks on results of integration tests to ensure quality criteria are met
install - install the package into the local repository, for use as a dependency in other
projects locally
deploy - done in the build environment, copies the final package to the remote repository for
sharing with other developers and projects.
it's possible to overload main in Java but it's not possible to override it, simply because it's a
static method. JVM always calls the original main method and if it doesn't found in class then it
throws java.lang.NoSuchMethodError: main Exception in thread "main" error at runtime.
Overloading means the same method name but different parameters, and
overriding means the same method name in a subclass with the same
parameters. So its not possible for overloading and overriding to happen at
the same time because overloading implies different parameters.
29. Can we overload and override constructor?
No it is not possible to override a constructor. If we try to do this then compiler error will come.
And it is never possible in Java.
Apache POI in Selenium is a widely used API for selenium data driven testing API that offers a
collection of Java libraries that helps us to read, write, and manipulate different Microsoft files such
as excel sheets, power-point, and word files.Users can easily create, modify and read/write into
excel files. POI stands for “Poor Obfuscation Implementation.”
Term Details
A workbook represents a Microsoft Excel file. It can be used
Workb
for creating and maintaining the spreadsheet. A workbook
ook
may contain many sheets.
A sheet refers to a page in a Microsoft Excel file that
Sheet
contains the number of rows and columns.
A row represents a collection of cells, which is used to
Row
represent a row in the spreadsheet.
A cell is indicated by a row and column combination. Data
Cell entered by a user is stored in a cell. Data can be of the type
such as string, numeric value, or formula.
data = getExcelData();
return data(); }
}} return testdata; }
@Test(dataProvider=”logindata”)
While(rowiterator.hasnext()){
While(columniterator.hasnext()){
usingPOI.readexcel();
File writer – Straight forward,direct interaction with files – Performance issue long codes,repeat line
Buffered Writer – Easiest Way, performance wise better and widely used
Filewriter.writer(content);
Filewriter.close();
BufferWriter.writer(content);
BufferWriter.close();
outputstream.writer(fileout);
outputstream.close();
Files.write(path, content.getBytes());
Buffered Reader – Easiest & simplest way, performance wise better and widely used
//1.For file reading we need location,
Sys.out.print(“currentline”);
String currentline;
While((currentline = reader.readline())!=null){
Sys.out.print(“currentline”);}
TESTNG:
Verbose = numbers
It will display the level of information in Test Report table after executing the test cases using
TestNG Suite.
<Suite>
<Test>
<Parameter>
<Classes>
@Test
@Parameters(“Parameter Name”)
Include parallel in Suite -> <Suite name=”Test Suite” verbose =”2” Parallel = “methods”
thread count =”2”> // Thread means number of process in parallel testing
How to assert in TestNG, Assert.assertEquals( Actual, expected) /This is to check string values, If not
equals means will get Assertertion error
@BeforeSuite
@BeforeTest
@BeforeClass
@BeforeMethod
@AfterMethod
@AfterClass
@AfterTest
@AfterSuite
TestNG Listeners: It is an interface that modifies the TestNG behaviour. Listeners. When the test
case failure occurs, then it is redirected to the new block written for the screenshot. (SDET Video)
OnTestSuccess()
OnTestFailure()
OnTestSkip()
OnFinish()
We can manually run using testng-failed.xml // This will be created in Test Output folder
Using IRetryAnalyzer Interface //This will create a Boolean retry method to run the test
under if condition to retry within the specified limit. This will execute @Test Level
Using IAnnotationTransformer and IRetryAnalyzer //IAnnotationTransformer which is
dependent of IRetryAnalyzer, for this Listeners will be added in TestNG xml to retrieve the
testcases as per below. This will execute at Run Time.
<listener class name=”Package.Transformer”>
Window.location = ‘URL’
Sample Code:
webdriverManager.Chromedriver().setup();
@Test(invocationCout = 3) // This invocationcount will rerun the same test multiple times as per
number entered
System.println(“QWERTY”);