Saturday, 22 September 2018

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.