Grid - SeeTest Client
1. Introduction
During an automation test Assertions or Exceptions can be thrown outside any context of the SeeTest client.
This fails the test, but because the exception isn't happening during any execution in the SeeTest Server, the test isn't shown in the report as Failed.
This library will report to the Grid reporter any exception or failed assertion and mark the test as failed.
2. Setup
Each testing framework have been split into 3 jars
- TestNG 6.9.10
- Junit 4.12
- Junit 5.2.0
2.1 Libraries bundled with SeeTest Client
Libraries are located under the client folder reporter <SeeTest installation folder>\clients\reporter\java
-
reporter-junit4.jar
-
reporter-junit5.jar
-
reporter-testng.jar
2.2 Libraries set as dependencies using local jar and global repository.
Gradle
//JUnit5
dependencies {
compile 'org.junit.jupiter:junit-jupiter-api:5.2.0'
compile '<seeTest Installation folder>\\clients\\reporter\\java\\reporter-junit5.jar'
//SeeTest Client
compile fileTree(dir: '<seeTest Installation folder>\\clients\\java', include: '*.jar')
}
//JUnit4
dependencies {
compile group: 'junit', name: 'junit', version: '4.12'
compile '<seeTest Installation folder>\\clients\\reporter\\java\\reporter-junit4.jar'
// SeeTest Client
compile fileTree(dir: '<seeTest Installation folder>\\clients\\java', include: '*.jar')
}
//TestNG
dependencies {
compile group: 'org.testng', name: 'testng', version: '6.9.10'
compile '<seeTest Installation folder>\\clients\\reporter\\java\\reporter-testng.jar'
// SeeTest Client
compile fileTree(dir: '<seeTest Installation folder>\\clients\\java', include: '*.jar')
}
Maven Dependencies
<!-- JUnit 5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>com.experitest</groupId>
<artifactId>reporter</artifactId>
<systemPath>${SeeTest.Installation.Folder}/reporter/java/reporter-junit5.jar</systemPath>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>4.1.2</version>
</dependency>
3. Code Usage:
3.1 Prerequisite
In order to get access to the client, it is mendatory that either one instance of the following object is a property on the test class
-
com.experitest.appium.SeeTestClient
-
com.experitest.client.Client
-
IOSDriver
-
AndroidDriver
3.1 JUnit4 using Runner
- First set the annotation relevant to the runner as class annotation
Class Anotation @RunWith
@RunWith(ReporterRunner.class)
public class SeeTestAutomationTestClass {
.....
- Then make sure you have one of the following class property, the name of the property is not important
Class Property
...
protected Client client;
protected GridClient grid = null;
private String accessKey = "eyJ4c.......";
final String HOST_NAME = "seetest.appium.pc";
private String host = "http://" + HOST_NAME + ":8080/wd/hub";
...
- Initialize the driver as you would usually do
Setup Driver
@Before
public void setup(){
System.out.println(">>>>>> I'm in Setup");
String name = testInfo.getTestMethod().get().getName();
Logger.setLevel(Level.DEBUG);
String deviceOS = "ios";
grid = new GridClient(accessKey, host);
client = grid.lockDeviceForExecution(name, "@os='" + deviceOS + "'", 10, 50000);
client.setReporter("xml", "reports", name);
}
@After
public void tearDown() {
System.out.println(">>>>>> Before closing driver");
client.generateReport(false);
client.releaseClient();
System.out.println(">>>>>> Reports generated");
}
- Run a test that generate an exception
Test method
@Test
public void dividedByZero() {
System.out.println(">>>>>> I'm in method divided by zero");
int e = 1 / 0;
}
3.2 JUnit4 using a Rule
- First set the Rule declaration
Class Anotation @RunWith
public class SeeTestAutomationTestClass {
@Rule
public ReporterRule reporterRule = new ReporterRule(this);
- Then make sure you have one of the following class property, the name of the property is not important
Class Property
...
protected Client client;
protected GridClient grid = null;
private String accessKey = "eyJ4c.......";
final String HOST_NAME = "seetest.appium.pc";
private String host = "http://" + HOST_NAME + ":8080/wd/hub";
...
- Initialize the driver as you would usually do
Setup Driver
@Before
public void setup(){
System.out.println(">>>>>> I'm in Setup");
String name = testInfo.getTestMethod().get().getName();
Logger.setLevel(Level.DEBUG);
String deviceOS = "ios";
grid = new GridClient(accessKey, host);
client = grid.lockDeviceForExecution(name, "@os='" + deviceOS + "'", 10, 50000);
client.setReporter("xml", "reports", name);
}
- Replace all references from @After to @AfterWithSeeTestReporter
@AfterWithSeeTestReporter method
@AfterWithSeeTestReporter
public void tearDown() {
System.out.println(">>>>>> Before closing driver");
client.generateReport(false);
client.releaseClient();
System.out.println(">>>>>> Reports generated");
}
@After can't be used because it runs before we get to the part the failed status is sent to the server thus closing the driver will cause the setReporterStatus request to fail. So another annotation ( @AfterWithSeeTestReporter ) is used to replace it This will call the tearDown right after the status is sent.
- Run a test that generate an exception
Test method
@Test
public void dividedByZero() {
System.out.println(">>>>>> I'm in method divided by zero");
int e = 1 / 0;
}
3.3 JUnit5
- First set the annotation relevant to the runner as class annotation
Class Anotation @RunWith
@ExtendWith(SeeTestReporterExceptionExtension.class)
public class SeeTestAutomationTestClass {
.....
- Then make sure you have one of the following class property, the name of the property is not important
Class Property
...
protected Client client;
protected GridClient grid = null;
private String accessKey = "eyJ4c.......";
final String HOST_NAME = "seetest.appium.pc";
private String host = "http://" + HOST_NAME + ":8080/wd/hub";
...
- Initialize the driver as you would usually do
Setup Driver
@BeforeEach
public void setup(){
System.out.println(">>>>>> I'm in Setup");
String name = testInfo.getTestMethod().get().getName();
Logger.setLevel(Level.DEBUG);
String deviceOS = "ios";
grid = new GridClient(accessKey, host);
client = grid.lockDeviceForExecution(name, "@os='" + deviceOS + "'", 10, 50000);
client.setReporter("xml", "reports", name);
}
@AfterEach
public void tearDown() {
System.out.println(">>>>>> Before closing driver");
client.generateReport(false);
client.releaseClient();
System.out.println(">>>>>> Reports generated");
}
- Run a test that generate an exception
Test method
@Test
public void dividedByZero() {
System.out.println(">>>>>> I'm in method divided by zero");
int e = 1 / 0;
}
3.4 TestNG
There are many ways to configure a listener in TestNG
In this example we are going to use an XML definition file
Test Suite Definition
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Log Suite Example" verbose="1">
<listeners>
<listener class-name="com.experitest.reporter.testng.Listener" />
</listeners>
<test name="TestNG logs sample" preserve-order="true">
<classes>
<class name="com.experitest.testng.AppiumDriver">
<methods>
<include name="methodPass" />
<include name="dividedByZero" />
<include name="methodSkip" />
</methods>
</class>
</classes>
</test>
</suite>
- First set the class according to the XML
Class Declaration
package com.experitest.testng;
.....
public class AppiumDriver {
.....
- Then make sure you have one of the following class property, the name of the property is not important
Class Property
...
protected Client client;
protected GridClient grid = null;
private String accessKey = "eyJ4c.......";
final String HOST_NAME = "seetest.appium.pc";
private String host = "http://" + HOST_NAME + ":8080/wd/hub";
...
- Initialize the driver as you would usually do
Setup Driver
@BeforeMethod
public void setup(){
System.out.println(">>>>>> I'm in Setup");
String name = testInfo.getTestMethod().get().getName();
Logger.setLevel(Level.DEBUG);
String deviceOS = "ios";
grid = new GridClient(accessKey, host);
client = grid.lockDeviceForExecution(name, "@os='" + deviceOS + "'", 10, 50000);
client.setReporter("xml", "reports", name);
}
@AfterMethod
public void tearDown() {
System.out.println(">>>>>> Before closing driver");
client.generateReport(false);
client.releaseClient();
System.out.println(">>>>>> Reports generated");
}
- Run a test that generate an exception
Test method
@Test(priority = 0)
public void methodPass() {
System.out.println(">>>>>> I'm in method pass");
}
@Test(priority = 1)
public void dividedByZero() {
System.out.println(">>>>>> I'm in method divided by zero");
int e = 1 / 0;
}
@Test(dependsOnMethods = { "dividedByZero" })
public void methodSkip() {
System.out.println(">>>>>> I'm in method skip");
}