Tuesday, 18 September 2018
Monday, 17 September 2018
TestNg | Rerun a failed test case ; Amazon interview qn
Option# 1. testng-failed.xml file in test-output directly
when we run any test suite tesng generates testng-failed.xml file if any failure happens. Just go there and right click on it and Run it.
Option#2 IRetryAnalyzer
public class Retry implements IRetryAnalyzer{
int count =0, retryCount = 3;
public boolean retry(ITestResult result){
if(count<retryCount){
count++;
return true;
}
}
}
In Test file
@Test(retryAnalizer=Retry.class)
public void m1(){
}
Option#3: IAnnotationTransformer
a. Use the same Retry class here
b. public class Transformation implement IAnnotationTrnasformer
{
@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor,Method test method){
IRetryAnalyzer retry = annotation.getRetryAnalyzer();
if(retry == null){
annoatation.setRetryAnalyzer(Retry.class);
}
}
}
c. add a listener
<listeners>
<listener class-name="com.google.Transformation">
</listners>
when we run any test suite tesng generates testng-failed.xml file if any failure happens. Just go there and right click on it and Run it.
Option#2 IRetryAnalyzer
public class Retry implements IRetryAnalyzer{
int count =0, retryCount = 3;
public boolean retry(ITestResult result){
if(count<retryCount){
count++;
return true;
}
}
}
In Test file
@Test(retryAnalizer=Retry.class)
public void m1(){
}
Option#3: IAnnotationTransformer
a. Use the same Retry class here
b. public class Transformation implement IAnnotationTrnasformer
{
@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor,Method test method){
IRetryAnalyzer retry = annotation.getRetryAnalyzer();
if(retry == null){
annoatation.setRetryAnalyzer(Retry.class);
}
}
}
c. add a listener
<listeners>
<listener class-name="com.google.Transformation">
</listners>
TestNG : Hard vs Soft assertion
Soft : Test Fails for sure, but execution Do not Stops even any assertion condition fails.
SoftAssert s = new SoftAssert();
s.assertEquls(1,1);
s.assertEquls(2,1);
s.assertAll();
Hard: Test Fails & STOPS then and their where any assertion condition fails.
Assertion a = new Assertion();
a.assertEquls(1,1);
SoftAssert s = new SoftAssert();
s.assertEquls(1,1);
s.assertEquls(2,1);
s.assertAll();
Hard: Test Fails & STOPS then and their where any assertion condition fails.
Assertion a = new Assertion();
a.assertEquls(1,1);
Testng - how to skip a test case at run time
@Test
public void m1(){
if(aboveMethodFailed)
throw new SkipException("Skipped");
}
using
throw new SkipException("Skipped"); statement we can skip an test case.
public void m1(){
if(aboveMethodFailed)
throw new SkipException("Skipped");
}
using
throw new SkipException("Skipped"); statement we can skip an test case.
Thursday, 16 August 2018
Report NG reports
Report NG report config is quite simple.
1. add dependencies
2. add listeners
3. Verify reports in test-output/HTML folder
As we are aware these ReportNG reports are beautiful than default TestNG reports
Maven dependenciets
<!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/velocity/velocity-dep -->
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity-dep</artifactId>
<version>1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
Add listeners in testng.xml
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
Thursday, 7 June 2018
RemoteWebDriver vs AppiumDriver vs AndroidDriver vs IOSDriver
RemoteWebDriver: This driver class comes directly from the upstream Selenium project. This is a pretty generic driver where initializing the driver means making network requests to a Selenium hub to start a driver session. Since Appium operates on the client-server model, Appium uses this to initialize a driver session. However, directly using the RemoteWebDriver is not recommended since there are other drivers available that offer additional features or convenience functions.
AppiumDriver: This driver class inherits from the RemoteWebDriver class, but it adds in additional functions that are useful in the context of a mobile automation test through the Appium server.
AndroidDriver: This driver class inherits from AppiumDriver, but it adds in additional functions that are useful in the context of a mobile automation test on Android devices through Appium. Only use this driver class if you want to start a test on an Android device or Android emulator.
IOSDriver: This driver class inherits from AppiumDriver, but it adds in additional functions that are useful in the context of a mobile automation test on iOS devices through Appium. Only use this driver class if you want to start a test on an iOS device or iOS emulator.
As you can see, the drivers and their names tie in closely with what they do. When it comes to initializing a driver, only use the Android or IOS drivers.
AppiumDriver: This driver class inherits from the RemoteWebDriver class, but it adds in additional functions that are useful in the context of a mobile automation test through the Appium server.
AndroidDriver: This driver class inherits from AppiumDriver, but it adds in additional functions that are useful in the context of a mobile automation test on Android devices through Appium. Only use this driver class if you want to start a test on an Android device or Android emulator.
IOSDriver: This driver class inherits from AppiumDriver, but it adds in additional functions that are useful in the context of a mobile automation test on iOS devices through Appium. Only use this driver class if you want to start a test on an iOS device or iOS emulator.
As you can see, the drivers and their names tie in closely with what they do. When it comes to initializing a driver, only use the Android or IOS drivers.
Subscribe to:
Posts (Atom)