diff --git a/api.v2/java.v2/JAVA_INTEGRATION_SAMPLE.iml b/api.v2/java.v2/JAVA_INTEGRATION_SAMPLE.iml index bb0b163..8c734fd 100644 --- a/api.v2/java.v2/JAVA_INTEGRATION_SAMPLE.iml +++ b/api.v2/java.v2/JAVA_INTEGRATION_SAMPLE.iml @@ -1,6 +1,6 @@ - + @@ -32,7 +32,6 @@ - @@ -42,8 +41,10 @@ - - + + + + @@ -69,5 +70,19 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api.v2/java.v2/README.md b/api.v2/java.v2/README.md index 2fbf0ee..a18977b 100644 --- a/api.v2/java.v2/README.md +++ b/api.v2/java.v2/README.md @@ -3,3 +3,32 @@ Each of PractiTest API methods are any of the following HTTP requests: GET,POST, PUT and DELETE. In the PractiTest API V2 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= +DEVELOPER_EMAIL= +API_TOKEN= +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= \ No newline at end of file diff --git a/api.v2/java.v2/pom.xml b/api.v2/java.v2/pom.xml index 46239c8..6d14f2c 100644 --- a/api.v2/java.v2/pom.xml +++ b/api.v2/java.v2/pom.xml @@ -7,6 +7,18 @@ JAVA_INTEGRATION_SAMPLE JAVA_INTEGRATION_SAMPLE 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + @@ -30,6 +42,45 @@ jackson-mapper-asl 1.9.2 + + com.google.guava + guava + 21.0 + + + info.cukes + cucumber-java8 + 1.2.5 + test + + + info.cukes + cucumber-testng + 1.2.5 + + + info.cukes + cucumber-picocontainer + 1.2.5 + test + + + log4j + log4j + 1.2.17 + + + + org.testng + testng + 6.13 + test + + + org.testng + testng + 6.11 + diff --git a/api.v2/java.v2/src/main/java/com/Config/GeneralConfig.java b/api.v2/java.v2/src/main/java/com/Config/GeneralConfig.java new file mode 100644 index 0000000..428e3df --- /dev/null +++ b/api.v2/java.v2/src/main/java/com/Config/GeneralConfig.java @@ -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 instanceContainer = new ThreadLocal(){ + @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; + } +} diff --git a/api.v2/java.v2/src/main/java/com/listeners/CucumberJVMListenerForPractiTest.java b/api.v2/java.v2/src/main/java/com/listeners/CucumberJVMListenerForPractiTest.java new file mode 100644 index 0000000..2688e0a --- /dev/null +++ b/api.v2/java.v2/src/main/java/com/listeners/CucumberJVMListenerForPractiTest.java @@ -0,0 +1,6 @@ +package com.listeners; + +public class CucumberJVMListenerForPractiTest { + + //TODO: implement Cucumber Listener +} diff --git a/api.v2/java.v2/src/main/java/com/listeners/JUnitListenerForPractiTest.java b/api.v2/java.v2/src/main/java/com/listeners/JUnitListenerForPractiTest.java new file mode 100644 index 0000000..3672205 --- /dev/null +++ b/api.v2/java.v2/src/main/java/com/listeners/JUnitListenerForPractiTest.java @@ -0,0 +1,6 @@ +package com.listeners; + +public class JUnitListenerForPractiTest { + + //TODO: implement Junit Listener +} diff --git a/api.v2/java.v2/src/main/java/com/listeners/TestNGListenerForPractiTest.java b/api.v2/java.v2/src/main/java/com/listeners/TestNGListenerForPractiTest.java new file mode 100644 index 0000000..232ba41 --- /dev/null +++ b/api.v2/java.v2/src/main/java/com/listeners/TestNGListenerForPractiTest.java @@ -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 instanceID = PractiTestWriter.getInstancesByTestIDAndTestSetID(result.getMethod().getDescription(), this.setID); + PractiTestWriter.submitResults(instanceID.get(0), 0); + } + + @Override + public void onTestFailure(ITestResult result) { + List 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 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 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) { + } +} diff --git a/api.v2/java.v2/src/main/java/com/practitest/api/common/RequestFactory.java b/api.v2/java.v2/src/main/java/com/practitest/api/common/RequestFactory.java index 76d5b87..ea28726 100644 --- a/api.v2/java.v2/src/main/java/com/practitest/api/common/RequestFactory.java +++ b/api.v2/java.v2/src/main/java/com/practitest/api/common/RequestFactory.java @@ -1,41 +1,26 @@ package com.practitest.api.common; +import com.Config.GeneralConfig; import com.jayway.restassured.RestAssured; import com.jayway.restassured.response.Response; import org.apache.commons.codec.binary.Base64; -import java.io.FileInputStream; -import java.util.Properties; - import static com.jayway.restassured.RestAssured.given; import static com.jayway.restassured.config.SSLConfig.sslConfig; public class RequestFactory { - private static Properties props = new Properties(); - - private static void loadProperties() - { - try{ - props.load(new FileInputStream("src/main/resources/project.properties")); - } - catch (Exception e) - { - e.printStackTrace(); - } - } + private static String URI = GeneralConfig.getConfigurationValue(GeneralConfig.URI); private static byte[] encoding(){ - loadProperties(); - return Base64.encodeBase64((props.getProperty("DEVELOPER_EMAIL") + ":" + props.getProperty("API_TOKEN")).getBytes()); + return Base64.encodeBase64((GeneralConfig.getConfigurationValue(GeneralConfig.DEV_MAIL) + ":" + GeneralConfig.getConfigurationValue(GeneralConfig.API_TOKEN)).getBytes()); } public static Response doGet(String apiEndPoint) { - loadProperties(); System.out.println("================================================================================"); - System.out.println("GET "+props.getProperty("URI")+apiEndPoint); + System.out.println("GET "+ URI+apiEndPoint); System.out.println("================================================================================"); return given() .log().headers() @@ -43,15 +28,14 @@ public static Response doGet(String apiEndPoint) .config(RestAssured.config().sslConfig(sslConfig().relaxedHTTPSValidation())) .header("Content-Type", "application/json") .header("Authorization", "Basic " + new String(encoding())) - .get(props.getProperty("URI")+apiEndPoint) + .get(URI+apiEndPoint) .then().extract().response(); } public static Response doPost(String apiEndPoint, String body) { - loadProperties(); System.out.println("================================================================================"); - System.out.println("POST "+props.getProperty("URI")+apiEndPoint); + System.out.println("POST "+URI+apiEndPoint); System.out.println("================================================================================"); return given() .log().headers() @@ -60,15 +44,14 @@ public static Response doPost(String apiEndPoint, String body) .header("Content-Type", "application/json") .header("Authorization", "Basic " + new String(encoding())) .body(body) - .post(props.getProperty("URI")+apiEndPoint) + .post(URI+apiEndPoint) .then().extract().response(); } public static Response doPost(String apiEndPoint, Object body) { - loadProperties(); System.out.println("================================================================================"); - System.out.println("POST "+props.getProperty("URI")+apiEndPoint); + System.out.println("POST "+URI+apiEndPoint); System.out.println("================================================================================"); return given() .log().headers() @@ -77,15 +60,14 @@ public static Response doPost(String apiEndPoint, Object body) .header("Content-Type", "application/json") .header("Authorization", "Basic " + new String(encoding())) .body(body) - .post(props.getProperty("URI")+apiEndPoint) + .post(URI+apiEndPoint) .then().extract().response(); } public static Response doPut(String apiEndPoint, String body) { - loadProperties(); System.out.println("================================================================================"); - System.out.println("PUT "+props.getProperty("URI")+apiEndPoint); + System.out.println("PUT "+URI+apiEndPoint); System.out.println("================================================================================"); return given() .log().headers() @@ -94,15 +76,14 @@ public static Response doPut(String apiEndPoint, String body) .header("Content-Type", "application/json") .header("Authorization", "Basic " + new String(encoding())) .body(body) - .put(props.getProperty("URI")+apiEndPoint) + .put(URI+apiEndPoint) .then().extract().response(); } public static Response doDelete(String apiEndPoint, String body) { - loadProperties(); System.out.println("================================================================================"); - System.out.println("DELETE "+props.getProperty("URI")+apiEndPoint); + System.out.println("DELETE "+URI+apiEndPoint); System.out.println("================================================================================"); return given() .log().headers() @@ -111,7 +92,7 @@ public static Response doDelete(String apiEndPoint, String body) .header("Content-Type", "application/json") .header("Authorization", "Basic " + new String(encoding())) .body(body) - .delete(props.getProperty("URI")+apiEndPoint) + .delete(URI+apiEndPoint) .then().extract().response(); } } diff --git a/api.v2/java.v2/src/main/java/com/practitest/api/example/PractiTestAPI.java b/api.v2/java.v2/src/main/java/com/practitest/api/example/PractiTestAPI.java index e64b1e7..14dec7c 100644 --- a/api.v2/java.v2/src/main/java/com/practitest/api/example/PractiTestAPI.java +++ b/api.v2/java.v2/src/main/java/com/practitest/api/example/PractiTestAPI.java @@ -1,60 +1,198 @@ package com.practitest.api.example; +import com.Config.GeneralConfig; +import com.jayway.restassured.response.Response; import com.practitest.api.common.RequestFactory; import com.practitest.api.model.instance.InstanceModel; import com.practitest.api.model.runs.*; import com.practitest.api.model.sets.Instances; import com.practitest.api.model.sets.SetsModel; -import com.jayway.restassured.response.Response; +import org.testng.Assert; import java.util.List; public class PractiTestAPI { + + + /** + * Reads project.properties file for projectID + */ + private static String projectID = GeneralConfig.getConfigurationValue(GeneralConfig.PROJECT_ID); + + /** + * + * @param id + * @return + */ public static Response sendGetSteps(String id) { - return RequestFactory.doGet("com/v2/projects/4650/steps.json?test-ids=" +id); + return RequestFactory.doGet("/api/v2/projects/"+projectID+"/steps.json?test-ids=" +id); } +// +// /** +// * +// * @param body +// */ +// public static void sendCreateRun(String body) +// { +// RequestFactory.doPost("/v2/projects/"+projectID+"/runs.json", body); +// } - public static void sendCreateRun(String body) + /** + * + * @param instanceID + * @param step + * @return + */ + public static Response sendCreateRun(String instanceID, List step) { - RequestFactory.doPost("com/v2/projects/4650/runs.json", body).prettyPrint(); + Data data = new Data(); + data.setType("instances"); + data.setAttributes(new Attributes(instanceID, 0)); + data.setSteps(new Steps(step)); + return RequestFactory.doPost("/api/v2/projects/"+projectID+"/runs.json", new RunsModel(data)).getBody().jsonPath().get("data.id"); } - public static void sendCreateRun(int instanceID, List step) + /** + * + * @param instanceID + * @return + */ + public static Response sendCreateRun(String instanceID) { Data data = new Data(); data.setType("instances"); - data.setAttributes(new Attributes(instanceID)); - data.setSteps(new Steps(step)); - RequestFactory.doPost("com/v2/projects/4650/runs.json", new RunsModel(data)).prettyPrint(); + data.setAttributes(new Attributes(instanceID, 0)); + return RequestFactory.doPost("/api/v2/projects/"+projectID+"/runs.json", new RunsModel(data)).getBody().jsonPath().get("data.id"); + } + + /** + * + * @param instanceID + * @return + */ + public static Response sendSubmitResult(String instanceID, int exitCode) + { + Data data = new Data(); + data.setType("instances"); + data.setAttributes(new Attributes(instanceID, exitCode)); + Response response = RequestFactory.doPost("/api/v2/projects/"+projectID+"/runs.json", new RunsModel(data)); + response.prettyPrint(); + return response; + } + + /** + * + * @param instanceID + * @return + */ + public static Response sendSubmitResult(String instanceID, String error, int exitCode) { + Data data = new Data(); + data.setType("instances"); + Attributes attributes = new Attributes(); + attributes.setExitcode(exitCode); + attributes.setInstanceid(instanceID); + attributes.setAutomatedExecutionOutput(error); + data.setAttributes(attributes); + Response response = RequestFactory.doPost("/api/v2/projects/" + projectID + "/runs.json", new RunsModel(data)); + response.prettyPrint(); + return response; } + /** + * + * @param body + */ public static void sendCreateInstance(String body) { - RequestFactory.doPost("com/v2/projects/4650/instances.json", body).prettyPrint(); + RequestFactory.doPost("/api/v2/projects/"+projectID+"/instances.json", body).prettyPrint(); } - public static void sendCreateInstance(int setID, int testID) + public static Response sendGetInstances(String testSetID) + { + return RequestFactory.doGet("/api/v2/projects/"+projectID+"/instances.json?set-ids="+testSetID); + } + + public static Response sendGetInstanceBytestID(Integer testID) + { + return RequestFactory.doGet("/api/v2/projects/"+projectID+"/instances.json?test-ids="+testID.toString()); + } + + public static Response sendGetInstanceByTestIDAndTestSetID(String testID, String testSetID) + { + Response response = RequestFactory.doGet("/api/v2/projects/"+projectID+"/instances.json?test-ids="+testID+"&set-ids="+testSetID); + response.prettyPrint(); + return response; + } + + public static Response sendRemoveInstance(Integer instanceID) + { + return RequestFactory.doDelete("/api/v2/projects/"+projectID+"/instances/"+instanceID.toString()+".json", ""); + } + + /** + * + * @param setID + * @param testID + * @return + */ + public static Response sendCreateInstance(String setID, int testID) { com.practitest.api.model.instance.Data data = new com.practitest.api.model.instance.Data(); data.setAttributes(new com.practitest.api.model.instance.Attributes(setID, testID)); + Response response = RequestFactory.doPost("/api/v2/projects/"+projectID+"/instances.json", new InstanceModel(data)); + response.prettyPrint(); + return response; + } - RequestFactory.doPost("com/v2/projects/4650/instances.json", new InstanceModel(data)).prettyPrint(); + /** + * + * @param body + * @return + */ + public static Response sendCreateTestSet(String body) + { + return RequestFactory.doPost("/api/v2/projects/"+projectID+"/sets.json", body); + } + + /** + * + * @return + */ + public static Response sendGetTestSet() + { + return RequestFactory.doGet("/api/v2/projects/"+projectID+"/sets.json"); } - public static void sendCreateTestSet(String body) + /** + * + * @return + */ + public static Response sendGetTestSetByName(String nameExect) { - RequestFactory.doPost("com/v2/projects/4650/sets.json", body).prettyPrint(); + if(nameExect == null) + { + Assert.fail("Please provide test set name"); + } + return RequestFactory.doGet("/api/v2/projects/"+projectID+"/sets.json?name_like="+nameExect); } - public static void sendCreateTestSet(String name, List testIDs) + /** + * + * @param name + * @param testIDs + * @return + */ + public static Response sendCreateTestSet(String name, List testIDs) { com.practitest.api.model.sets.Data data = new com.practitest.api.model.sets.Data(); data.setInstances(new Instances(testIDs)); data.setAttributes(new com.practitest.api.model.sets.Attributes(name)); - RequestFactory.doPost("com/v2/projects/4650/sets.json", new SetsModel(data)).prettyPrint(); + Response response = RequestFactory.doPost("/api/v2/projects/"+projectID+"/sets.json", new SetsModel(data)); + response.prettyPrint(); + return response; } diff --git a/api.v2/java.v2/src/main/java/com/practitest/api/example/PractiTestWriter.java b/api.v2/java.v2/src/main/java/com/practitest/api/example/PractiTestWriter.java new file mode 100644 index 0000000..fa647ab --- /dev/null +++ b/api.v2/java.v2/src/main/java/com/practitest/api/example/PractiTestWriter.java @@ -0,0 +1,111 @@ +package com.practitest.api.example; + +import com.Config.GeneralConfig; +import com.jayway.restassured.response.Response; +import com.practitest.api.model.runs.StepModel; + +import java.util.List; + +public class PractiTestWriter { + + /** + * + * @return set id for the project + */ + public static String getSetID(String setName) + { + + Response response = PractiTestAPI.sendGetTestSetByName(setName); + response.prettyPrint(); + try + { + return response.getBody().jsonPath().get("data.id"); + } + catch (Exception e) + { + return null; + } + } + + /** + * + * @param testIDs List of tests which should be assigned to this Test Set + * @return new TestSetID + */ + public static String createNewSet(List testIDs) + { + Response response = PractiTestAPI.sendCreateTestSet(GeneralConfig.getConfigurationValue("groups"), testIDs);//System.getProperty("groups"), testIDs); // + response.prettyPrint(); + return response.getBody().jsonPath().get("data.id") ; + } + + /** + * + * @param setID TestSet ID which should be used for new Instance + * @param testID TestCase ID which should be used to create new instance + * @return new Instance ID + */ + public static String createNewInstance(String setID, Integer testID) + { + return PractiTestAPI.sendCreateInstance(setID, testID).getBody().jsonPath().get("data.id"); + } + + public static void createAllInstances(String setID, List testID) + { + for (int i =0; i getInstancesByTestSetID(String testSet) + { + return PractiTestAPI.sendGetInstances(testSet).body().jsonPath().get("data.id"); + } + + public static Integer getInstancesByTestID(Integer testID) + { + return PractiTestAPI.sendGetInstanceBytestID(testID).body().jsonPath().get("data.id"); + } + + public static List getInstancesByTestIDAndTestSetID(String testID, String testSetID) + { + return PractiTestAPI.sendGetInstanceByTestIDAndTestSetID(testID, testSetID).body().jsonPath().get("data.id"); + } + + public static List getTestIDsForTestSetID(String testSet) + { + return PractiTestAPI.sendGetInstances(testSet).body().jsonPath().get("data.attributes.test-id"); + } + + public static void removeInstance(Integer instanceID) + { + PractiTestAPI.sendRemoveInstance(instanceID); + } + + /** + * + * @param instanceID instance ID for test execution + * @param stepModel step Model which was used for this test + * @return extracts result ID for further usage + */ + public static Integer submitResults(String instanceID, List stepModel) + { + return PractiTestAPI.sendCreateRun(instanceID, stepModel).getBody().jsonPath().get("get.id"); + } + + public static String submitResults(String instanceID, Integer statusCode) + { + return PractiTestAPI.sendSubmitResult(instanceID, statusCode).getBody().jsonPath().get("data.id"); + } + + public static String submitResults(String instanceID, String error, Integer statusCode) + { + return PractiTestAPI.sendSubmitResult(instanceID, error, statusCode).getBody().jsonPath().get("data.id"); + } + +} diff --git a/api.v2/java.v2/src/main/java/com/practitest/api/model/instance/Attributes.java b/api.v2/java.v2/src/main/java/com/practitest/api/model/instance/Attributes.java index 4a07755..0fe0bba 100644 --- a/api.v2/java.v2/src/main/java/com/practitest/api/model/instance/Attributes.java +++ b/api.v2/java.v2/src/main/java/com/practitest/api/model/instance/Attributes.java @@ -13,7 +13,7 @@ public class Attributes { @JsonProperty("set-id") - private int setId; + private String setId; @JsonProperty("test-id") private int testId; @@ -29,19 +29,19 @@ public Attributes() { * @param testId * @param setId */ - public Attributes(int setId, int testId) { + public Attributes(String setId, int testId) { super(); this.setId = setId; this.testId = testId; } @JsonProperty("set-id") - public int getSetId() { + public String getSetId() { return setId; } @JsonProperty("set-id") - public void setSetId(int setId) { + public void setSetId(String setId) { this.setId = setId; } diff --git a/api.v2/java.v2/src/main/java/com/practitest/api/model/runs/Attributes.java b/api.v2/java.v2/src/main/java/com/practitest/api/model/runs/Attributes.java index c768d31..61151b8 100644 --- a/api.v2/java.v2/src/main/java/com/practitest/api/model/runs/Attributes.java +++ b/api.v2/java.v2/src/main/java/com/practitest/api/model/runs/Attributes.java @@ -12,7 +12,16 @@ public class Attributes { @JsonProperty("instance-id") - private int instanceId; + private String instanceId; + + + + @JsonProperty("automated-execution-output") + private String automatedExecutionOutput; + + + @JsonProperty("exit-code") + private int exitcode; /** * No args constructor for use in serialization @@ -27,19 +36,47 @@ public Attributes() { */ - public Attributes(int instanceId) { + public Attributes(String instanceId, int exitcode) { + super(); + this.instanceId = instanceId; + this.exitcode = exitcode; + } + + public Attributes(String instanceId, String automatedExecutionOutput, int exitcode) { super(); this.instanceId = instanceId; + this.automatedExecutionOutput = automatedExecutionOutput; + this.exitcode = exitcode; } @JsonProperty("instance-id") - public int getInstanceid() { + public String getInstanceid() { return instanceId; } @JsonProperty("instance-id") - public void setInstanceid(int instanceId) { + public void setInstanceid(String instanceId) { this.instanceId = instanceId; } + @JsonProperty("exit-code") + public int getExitcode() { + return exitcode; + } + + @JsonProperty("exit-code") + public void setExitcode(int exitcode) { + this.exitcode = exitcode; + } + + @JsonProperty("automated-execution-output") + public String getAutomatedExecutionOutput() { + return automatedExecutionOutput; + } + + @JsonProperty("automated-execution-output") + public void setAutomatedExecutionOutput(String automatedExecutionOutput) { + this.automatedExecutionOutput = automatedExecutionOutput; + } + } diff --git a/api.v2/java.v2/src/main/java/com/practitest/integration/ExtractTests.java b/api.v2/java.v2/src/main/java/com/practitest/integration/ExtractTests.java new file mode 100644 index 0000000..82300d8 --- /dev/null +++ b/api.v2/java.v2/src/main/java/com/practitest/integration/ExtractTests.java @@ -0,0 +1,29 @@ +package com.practitest.integration; + +import com.webdriver.example.Utils.Log; +import org.testng.Assert; +import org.testng.ITestContext; +import org.testng.ITestNGMethod; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class ExtractTests { + + public static List extractAllTestIds(ITestContext context) + { + ITestNGMethod[] testMethods = context.getAllTestMethods(); + List testIds = new ArrayList(0); + if (testMethods.length == 0) + { + Log.error("PLEASE PROVIDE VALID GROUP NAME"); + Assert.fail("No test methods found for specified group"); + } + for (ITestNGMethod testMethod : testMethods) { + testIds.add(testMethod.getDescription()); + } + return testIds.stream().map(Integer::parseInt).collect(Collectors.toList()); + } + +} diff --git a/api.v2/java.v2/src/main/java/com/webdriver/example/DriverFactory.java b/api.v2/java.v2/src/main/java/com/webdriver/example/DriverFactory.java new file mode 100644 index 0000000..cf10912 --- /dev/null +++ b/api.v2/java.v2/src/main/java/com/webdriver/example/DriverFactory.java @@ -0,0 +1,31 @@ +package com.webdriver.example; + +import io.github.bonigarcia.wdm.ChromeDriverManager; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; + +public class DriverFactory { + + static{ + ChromeDriverManager.getInstance().arch64().setup(); + } + + + private static ThreadLocal driverContainer = new ThreadLocal<>(); + + + public static WebDriver getBrowserInstance(){ + return driverContainer.get(); + } + + public static WebDriver openChrome() { + + driverContainer.set(new ChromeDriver()); + return driverContainer.get(); + } + + public static void tearDown() { + driverContainer.get().quit(); + driverContainer.set(null); + } +} diff --git a/api.v2/java.v2/src/main/java/com/webdriver/example/Utils/Log.java b/api.v2/java.v2/src/main/java/com/webdriver/example/Utils/Log.java new file mode 100644 index 0000000..52b43b2 --- /dev/null +++ b/api.v2/java.v2/src/main/java/com/webdriver/example/Utils/Log.java @@ -0,0 +1,74 @@ +package com.webdriver.example.Utils; + +import org.apache.log4j.Logger; + +public class Log { + + // Initialize Log4j logs + + private static Logger Log = Logger.getLogger(Log.class.getName());// + + // This is to print log for the beginning of the test case, as we usually run so many test cases as a test suite + + public static void startTestCase(){ + + Log.info("****************************************************************************************"); + + Log.info("****************************************************************************************"); + + Log.info("$$$$$$$$$$$$$$$$$$$$$ -S-T-A-R-T- $$$$$$$$$$$$$$$$$$$$$$$$$"); + + Log.info("****************************************************************************************"); + + Log.info("****************************************************************************************"); + + } + + //This is to print log for the ending of the test case + + public static void endTestCase(){ + + Log.info("XXXXXXXXXXXXXXXXXXXXXXX "+"-E---N---D-"+" XXXXXXXXXXXXXXXXXXXXXX"); + + Log.info("X"); + + Log.info("X"); + + Log.info("X"); + + Log.info("X"); + + } + + // Need to create these methods, so that they can be called + + public static void info(String message) { + + Log.info(message); + + } + + public static void warn(String message) { + + Log.warn(message); + + } + + public static void error(String message) { + + Log.error(message); + + } + + public static void fatal(String message) { + + Log.fatal(message); + + } + + public static void debug(String message) { + + Log.debug(message); + + } +} diff --git a/api.v2/java.v2/src/main/resources/log4j.properties b/api.v2/java.v2/src/main/resources/log4j.properties new file mode 100644 index 0000000..499aa94 --- /dev/null +++ b/api.v2/java.v2/src/main/resources/log4j.properties @@ -0,0 +1,16 @@ +# Root logger option +log4j.rootLogger=INFO, recipt, stdout + +# Direct log messages to a log recipt +log4j.appender.recipt=org.apache.log4j.RollingFileAppender +log4j.appender.recipt.File=logging.log +log4j.appender.recipt.MaxFileSize=10MB +log4j.appender.recipt.MaxBackupIndex=10 +log4j.appender.recipt.layout=org.apache.log4j.PatternLayout +log4j.appender.recipt.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/api.v2/java.v2/src/main/resources/project.properties b/api.v2/java.v2/src/main/resources/project.properties index 2ac658e..95bf559 100644 --- a/api.v2/java.v2/src/main/resources/project.properties +++ b/api.v2/java.v2/src/main/resources/project.properties @@ -1,3 +1,4 @@ -URI=URI -DEVELOPER_EMAIL=developer@mail.com -API_TOKEN=TOKEN \ No newline at end of file +URI= +DEVELOPER_EMAIL= +API_TOKEN= +PROJECT_ID= \ No newline at end of file diff --git a/api.v2/java.v2/src/test/java/Cucumber/Hooks.java b/api.v2/java.v2/src/test/java/Cucumber/Hooks.java new file mode 100644 index 0000000..547dfbe --- /dev/null +++ b/api.v2/java.v2/src/test/java/Cucumber/Hooks.java @@ -0,0 +1,44 @@ +package Cucumber; + +import com.webdriver.example.DriverFactory; +import com.webdriver.example.Utils.Log; +import cucumber.api.Scenario; +import cucumber.api.java.After; +import cucumber.api.java.Before; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; +import org.openqa.selenium.WebDriverException; + +public class Hooks { + public static ThreadLocal lastScenario = new ThreadLocal<>(); + + @Before + public void openBrowser() { + Log.startTestCase(); + DriverFactory.openChrome(); + DriverFactory.getBrowserInstance().manage().window().maximize(); + } + + + @After + public void afterScenario(Scenario scenario) { + lastScenario.set(scenario); + try { + if (scenario.isFailed()) { + try { + scenario.write("Current Page URL is " + DriverFactory.getBrowserInstance().getCurrentUrl()); + byte[] screenshot = ((TakesScreenshot) DriverFactory.getBrowserInstance()).getScreenshotAs(OutputType.BYTES); + scenario.embed(screenshot, "image/png"); + } catch (WebDriverException somePlatformsDontSupportScreenshots) { + System.err.println(somePlatformsDontSupportScreenshots.getMessage()); + } + } + }finally { + DriverFactory.tearDown(); + //if (TestRailWriter.isIsTestRailActive()) { TODO: implement practitest usage + // TestRailWriter.afterScenario(); TODO: implement after scenario case usage + // } + Log.endTestCase(); + } + } +} diff --git a/api.v2/java.v2/src/test/java/RunWithTests.java b/api.v2/java.v2/src/test/java/RunWithTests.java index bbc0071..1016e70 100644 --- a/api.v2/java.v2/src/test/java/RunWithTests.java +++ b/api.v2/java.v2/src/test/java/RunWithTests.java @@ -35,7 +35,7 @@ public final static void main(String[] args) throws Exception{ PractiTestAPI.sendCreateTestSet("new testing", testIDs); //Create new instance - PractiTestAPI.sendCreateInstance(20803, 84149); + PractiTestAPI.sendCreateInstance("20803", 84149); //Setup chromeDriver ChromeDriverManager.getInstance().setup(); @@ -80,7 +80,7 @@ public final static void main(String[] args) throws Exception{ stepModel.add(step3); //Submit results - PractiTestAPI.sendCreateRun(101263, stepModel); + PractiTestAPI.sendCreateRun("101263", stepModel); } } diff --git a/api.v2/java.v2/src/test/java/TestNG/BaseTest.java b/api.v2/java.v2/src/test/java/TestNG/BaseTest.java new file mode 100644 index 0000000..574a794 --- /dev/null +++ b/api.v2/java.v2/src/test/java/TestNG/BaseTest.java @@ -0,0 +1,38 @@ +package TestNG; + +import com.webdriver.example.DriverFactory; +import com.webdriver.example.Utils.Log; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.BeforeTest; + +public class BaseTest { + + @BeforeSuite + public void beforeTestSuite() + { + + } + + @BeforeTest + public void beforeTest() + { + Log.startTestCase(); + DriverFactory.openChrome(); + DriverFactory.getBrowserInstance().manage().window().maximize(); + } + + @AfterTest + public void afterTest() + { + DriverFactory.tearDown(); + Log.endTestCase(); + } + + @AfterSuite + public void afterTestSuite() + { + + } +} diff --git a/api.v2/java.v2/src/test/java/TestNG/tests/SampleTest.java b/api.v2/java.v2/src/test/java/TestNG/tests/SampleTest.java new file mode 100644 index 0000000..5b0ed23 --- /dev/null +++ b/api.v2/java.v2/src/test/java/TestNG/tests/SampleTest.java @@ -0,0 +1,51 @@ +package TestNG.tests; + +import TestNG.BaseTest; +import com.listeners.TestNGListenerForPractiTest; +import com.webdriver.example.Utils.Log; +import org.testng.Assert; +import org.testng.annotations.Listeners; +import org.testng.annotations.Test; + +@Listeners(TestNGListenerForPractiTest.class) +public class SampleTest extends BaseTest{ + + + @Test(description = "84140", groups = "test") + public void googleTest() + { + Log.info("Just checking"); + } + + @Test(description = "84148", groups = "test2") + public void googleTest1() + { + Log.info("Just checking"); + Assert.fail(); + } + + @Test(description = "84142", groups = "test") + public void googleTest2() + { + Log.info("Just 4"); + } + + @Test(description = "84143", groups = "test2") + public void googleTest3() + { + Log.info("Just 6"); + } + + @Test(description = "84144", groups = "test") + public void googleTest4() + { + Log.info("Just 8"); + Assert.fail(); + } + + @Test(description = "84147", groups = "test2") + public void googleTest5() + { + Log.info("Just checking"); + } +} diff --git a/api.v2/java.v2/src/test/java/TestNG/tests/SampleTests2.java b/api.v2/java.v2/src/test/java/TestNG/tests/SampleTests2.java new file mode 100644 index 0000000..e884cb2 --- /dev/null +++ b/api.v2/java.v2/src/test/java/TestNG/tests/SampleTests2.java @@ -0,0 +1,47 @@ +package TestNG.tests; + +import com.listeners.TestNGListenerForPractiTest; +import com.webdriver.example.Utils.Log; +import org.testng.annotations.Listeners; +import org.testng.annotations.Test; + + +@Listeners(TestNGListenerForPractiTest.class) +public class SampleTests2 { + + @Test(description = "10") + public void googleTest() + { + Log.info("Just checking"); + } + + @Test(description = "12") + public void googleTest1() + { + Log.info("Just checking"); + } + + @Test(description = "13") + public void googleTest2() + { + Log.info("Just 4"); + } + + @Test(description = "15") + public void googleTest3() + { + Log.info("Just 6"); + } + + @Test(description = "17") + public void googleTest4() + { + Log.info("Just 8"); + } + + @Test(description = "19") + public void googleTest5() + { + Log.info("Just checking"); + } +} diff --git a/api.v2/java.v2/testNG.xml b/api.v2/java.v2/testNG.xml new file mode 100644 index 0000000..e34e1d3 --- /dev/null +++ b/api.v2/java.v2/testNG.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file