Wednesday, 19 September 2018

TestNG | Running suite file programmatically

public class MainTest {
    public static void main(String[] args){
    List<String> file = new ArrayList<String>();
    file.add("D:/Selenium_workspace/Framework/src/Framework.xml");
    TestNG testNG = new TestNG();
    testNG.setTestSuites(file);
    testNG.run();}
}

Tuesday, 18 September 2018

ATU reports download folder

https://drive.google.com/drive/folders/0B7rZvkq9tkwPMkJlUjJGTkJjOTA

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>

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);

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.

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>