Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestNG Practitest integration implementation #4

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions api.v2/java.v2/JAVA_INTEGRATION_SAMPLE.iml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
Expand Down Expand Up @@ -32,7 +32,6 @@
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-api:3.3.1" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib-nodep:3.2.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-exec:1.3" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" name="Maven: net.java.dev.jna:jna-platform:4.1.0" level="project" />
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:4.1.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-edge-driver:3.3.1" level="project" />
Expand All @@ -42,8 +41,10 @@
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-safari-driver:3.3.1" level="project" />
<orderEntry type="library" name="Maven: com.codeborne:phantomjsdriver:1.4.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:htmlunit-driver:2.24" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:3.7.1" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.7.5" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:3.11.0" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.7.9" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.9.1" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.13.0" level="project" />
<orderEntry type="library" name="Maven: net.sourceforge.htmlunit:htmlunit:2.24" level="project" />
<orderEntry type="library" name="Maven: xalan:xalan:2.7.2" level="project" />
<orderEntry type="library" name="Maven: xalan:serializer:2.7.2" level="project" />
Expand All @@ -69,5 +70,19 @@
<orderEntry type="library" name="Maven: org.jsoup:jsoup:1.10.2" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-mapper-asl:1.9.2" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-core-asl:1.9.2" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:cucumber-java8:1.2.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:cucumber-java:1.2.5" level="project" />
<orderEntry type="library" name="Maven: info.cukes:cucumber-testng:1.2.5" level="project" />
<orderEntry type="library" name="Maven: info.cukes:cucumber-core:1.2.5" level="project" />
<orderEntry type="library" name="Maven: info.cukes:cucumber-html:0.2.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:cucumber-picocontainer:1.2.5" level="project" />
<orderEntry type="library" name="Maven: info.cukes:cucumber-jvm-deps:1.0.5" level="project" />
<orderEntry type="library" name="Maven: info.cukes:gherkin:2.12.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.picocontainer:picocontainer:2.15" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="Maven: org.testng:testng:6.11" level="project" />
<orderEntry type="library" name="Maven: com.beust:jcommander:1.64" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
</component>
</module>
29 changes: 29 additions & 0 deletions api.v2/java.v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,32 @@
Each of PractiTest API methods are any of the following HTTP requests: GET,POST, PUT and DELETE.

In the <a href="https://www.practitest.com/api-v2/" target="_blank">PractiTest API V2</a> documentation, there are curl examples for each method (with one of the request types). If the curl begins with GET, you need to see the get_request file in your language. The same with the rest of the method types.

TestNG integration

Required project properties:

URI=<URI to PractiTest instance>
DEVELOPER_EMAIL=<developer mail>
API_TOKEN=<access token for API>
PROJECT_ID=<test project ID>


Supported browsers: Chrome

TestNG Class structure for PractiTest integration

Regular TestNG method which should have description and groups specified.
description == Test ID
groups == Set ID

groups is used for test cases filtering

Example:
@Test(description = "TEST_ID", groups = "SET_NAME")
public void googleTest()


Test execution using command line

mvn test -Dgroups=<YOUR SET NAME>
51 changes: 51 additions & 0 deletions api.v2/java.v2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
<groupId>JAVA_INTEGRATION_SAMPLE</groupId>
<artifactId>JAVA_INTEGRATION_SAMPLE</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>


<dependencies>
Expand All @@ -30,6 +42,45 @@
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
</dependency>
</dependencies>


Expand Down
67 changes: 67 additions & 0 deletions api.v2/java.v2/src/main/java/com/Config/GeneralConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.Config;

import com.webdriver.example.Utils.Log;

import java.io.FileInputStream;
import java.util.Properties;

public class GeneralConfig {

public static final String PROPERTIES_PATH = "src/main/resources/project.properties";
public static final String URI = "URI";
public static final String DEV_MAIL = "DEVELOPER_EMAIL";
public static final String API_TOKEN = "API_TOKEN";
public static final String PROJECT_ID = "PROJECT_ID";


protected static Properties m_props = new Properties();
private static boolean m_initialized = false;

// SINGLETON CONSTRUCTOR

GeneralConfig() {}

private static ThreadLocal<GeneralConfig> instanceContainer = new ThreadLocal<GeneralConfig>(){
@Override
protected GeneralConfig initialValue() {
return new GeneralConfig();
}
};

public static GeneralConfig getInstance() {
return instanceContainer.get();
}


public static boolean isInitialized() {
return m_initialized;
}

public static void loadConfig()
{
try{
m_props.load(new FileInputStream(PROPERTIES_PATH));
m_initialized = true;
}
catch (Exception e) {
e.printStackTrace();
Log.error("Unable to load parameters");
}
}



public static String getConfigurationValue(final String configurationName) {
if(!GeneralConfig.isInitialized())
throw new IllegalStateException("GeneralConfig is not initialized, please call GeneralConfig.loadConfig()");

return m_props.getProperty(configurationName);
}

/*
Should be used if any parameter should be modified during test execution
*/
public static boolean setConfigurationValue(final String configurationName, final String value) {
return m_props.setProperty(configurationName, value) != null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.listeners;

public class CucumberJVMListenerForPractiTest {

//TODO: implement Cucumber Listener
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.listeners;

public class JUnitListenerForPractiTest {

//TODO: implement Junit Listener
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.listeners;

import com.Config.GeneralConfig;
import com.practitest.api.example.PractiTestWriter;
import com.practitest.integration.ExtractTests;
import com.webdriver.example.Utils.Log;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

import java.util.List;

public class TestNGListenerForPractiTest implements ITestListener {

protected String setID = null;


@Override
public void onTestStart(ITestResult result) {
}

@Override
public void onTestSuccess(ITestResult result) {
List<String> instanceID = PractiTestWriter.getInstancesByTestIDAndTestSetID(result.getMethod().getDescription(), this.setID);
PractiTestWriter.submitResults(instanceID.get(0), 0);
}

@Override
public void onTestFailure(ITestResult result) {
List<String> instanceID = PractiTestWriter.getInstancesByTestIDAndTestSetID(result.getMethod().getDescription(), this.setID);

PractiTestWriter.submitResults(instanceID.get(0), result.getThrowable().getMessage(), 1);
}

@Override
public void onTestSkipped(ITestResult result) {
}

@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
}

@Override
public void onStart(ITestContext context) {
//Load configuration file
GeneralConfig.loadConfig();
//Check if Set ID specified is present in the system
String existingTestSetID = PractiTestWriter.getSetID(System.getProperty("groups"));
//extract all automated tests for current execution
List<Integer> testIDs = ExtractTests.extractAllTestIds(context);
if (existingTestSetID == null)
{
Log.info("Creating new test set");
this.setID = PractiTestWriter.createNewSet(testIDs);
}
else
{
this.setID = existingTestSetID;
//get test id's for existing TestSet
List<Integer> currentTestSetTestIDs = PractiTestWriter.getTestIDsForTestSetID(this.setID);
//Remove existing test IDs from List to get List of removed test cases in Practi test
currentTestSetTestIDs.removeAll(testIDs);
//Remove Instance IDs which are not present for this set IDs
for (Integer currentTestSetTestID : currentTestSetTestIDs) {
PractiTestWriter.removeInstance(PractiTestWriter.getInstancesByTestID(currentTestSetTestID));
}
Log.info("Using existing TestSEtID: "+existingTestSetID);
}
//Create new instances for all tests in TestSet
PractiTestWriter.createAllInstances(this.setID, testIDs);
String current = PractiTestWriter.getSetID("test2");
Log.info(current);
}


@Override
public void onFinish(ITestContext context) {
}
}
Loading