-
Notifications
You must be signed in to change notification settings - Fork 12
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
vdemkiv
wants to merge
10
commits into
PractiTest:master
Choose a base branch
from
vdemkiv:maven_integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
344af08
TestNG Practitest integration implementation
vdemkiv 71ab180
Update PractiTestAPI.java
13cd1c6
Existing Test Set iD usage implementation
vdemkiv baebba4
implementation based on code review comments from Stas.
vdemkiv acf1de9
missed file
vdemkiv 10ccf9a
fix all dependencies for project to be executable
vdemkiv dafa0fc
fixes for set creating. execution by groups
vdemkiv 789ce45
validation fix
vdemkiv 39f2a7a
Implemented proper usage for config load
vdemkiv 25642e2
updated readme.
vdemkiv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
api.v2/java.v2/src/main/java/com/listeners/CucumberJVMListenerForPractiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.listeners; | ||
|
||
public class CucumberJVMListenerForPractiTest { | ||
|
||
//TODO: implement Cucumber Listener | ||
} |
6 changes: 6 additions & 0 deletions
6
api.v2/java.v2/src/main/java/com/listeners/JUnitListenerForPractiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.listeners; | ||
|
||
public class JUnitListenerForPractiTest { | ||
|
||
//TODO: implement Junit Listener | ||
} |
48 changes: 48 additions & 0 deletions
48
api.v2/java.v2/src/main/java/com/listeners/TestNGListenerForPractiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.listeners; | ||
|
||
import com.practitest.api.example.PractiTestWriter; | ||
import com.practitest.integration.ExtractTests; | ||
import org.testng.ITestContext; | ||
import org.testng.ITestListener; | ||
import org.testng.ITestResult; | ||
|
||
import java.util.List; | ||
|
||
public class TestNGListenerForPractiTest implements ITestListener { | ||
|
||
|
||
@Override | ||
public void onTestStart(ITestResult result) { | ||
} | ||
|
||
@Override | ||
public void onTestSuccess(ITestResult result) { | ||
} | ||
|
||
@Override | ||
public void onTestFailure(ITestResult result) { | ||
} | ||
|
||
@Override | ||
public void onTestSkipped(ITestResult result) { | ||
} | ||
|
||
@Override | ||
public void onTestFailedButWithinSuccessPercentage(ITestResult result) { | ||
} | ||
|
||
@Override | ||
public void onStart(ITestContext context) { | ||
List<Integer> testIDs = ExtractTests.extractAllTestIds(context); | ||
//Create test run for all tests in current execution | ||
Integer setID = PractiTestWriter.createNewSet(testIDs); | ||
//Store SetID for further usage | ||
System.setProperty("currentSetId", setID.toString()); | ||
PractiTestWriter.createNewSet(testIDs); | ||
} | ||
|
||
|
||
@Override | ||
public void onFinish(ITestContext context) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,49 +12,59 @@ | |
|
||
public class PractiTestAPI { | ||
|
||
private final static String projectID = System.getProperty("PROJECT_ID"); | ||
|
||
public static Response sendGetSteps(String id) | ||
{ | ||
return RequestFactory.doGet("com/v2/projects/4650/steps.json?test-ids=" +id); | ||
return RequestFactory.doGet("com/v2/projects/"+projectID+"/steps.json?test-ids=" +id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the URL starts with 'com/'? |
||
} | ||
|
||
public static void sendCreateRun(String body) | ||
{ | ||
RequestFactory.doPost("com/v2/projects/4650/runs.json", body).prettyPrint(); | ||
RequestFactory.doPost("com/v2/projects/"+projectID+"/runs.json", body); | ||
} | ||
|
||
public static void sendCreateRun(int instanceID, List<StepModel> step) | ||
public static Response sendCreateRun(int instanceID, List<StepModel> step) | ||
{ | ||
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(); | ||
return RequestFactory.doPost("com/v2/projects/"+projectID+"/runs.json", new RunsModel(data)).getBody().jsonPath().get("data.id"); | ||
} | ||
|
||
public static Response sendCreateRun(int instanceID) | ||
{ | ||
Data data = new Data(); | ||
data.setType("instances"); | ||
data.setAttributes(new Attributes(instanceID)); | ||
return RequestFactory.doPost("com/v2/projects/"+projectID+"/runs.json", new RunsModel(data)).getBody().jsonPath().get("data.id"); | ||
} | ||
|
||
public static void sendCreateInstance(String body) | ||
{ | ||
RequestFactory.doPost("com/v2/projects/4650/instances.json", body).prettyPrint(); | ||
RequestFactory.doPost("com/v2/projects/"+projectID+"/instances.json", body).prettyPrint(); | ||
} | ||
|
||
public static void sendCreateInstance(int setID, int testID) | ||
public static Response sendCreateInstance(int 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)); | ||
|
||
RequestFactory.doPost("com/v2/projects/4650/instances.json", new InstanceModel(data)).prettyPrint(); | ||
return RequestFactory.doPost("com/v2/projects/"+projectID+"/instances.json", new InstanceModel(data)); | ||
} | ||
|
||
public static void sendCreateTestSet(String body) | ||
public static Response sendCreateTestSet(String body) | ||
{ | ||
RequestFactory.doPost("com/v2/projects/4650/sets.json", body).prettyPrint(); | ||
return RequestFactory.doPost("com/v2/projects/"+projectID+"/sets.json", body); | ||
} | ||
|
||
public static void sendCreateTestSet(String name, List<Integer> testIDs) | ||
public static Response sendCreateTestSet(String name, List<Integer> 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(); | ||
return RequestFactory.doPost("com/v2/projects/"+projectID+"/sets.json", new SetsModel(data)); | ||
} | ||
|
||
|
||
|
38 changes: 38 additions & 0 deletions
38
api.v2/java.v2/src/main/java/com/practitest/api/example/PractiTestWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.practitest.api.example; | ||
|
||
import com.jayway.restassured.response.Response; | ||
import com.practitest.api.model.runs.StepModel; | ||
|
||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
public class PractiTestWriter { | ||
|
||
private static String getNameForNewRun() { | ||
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); | ||
Date date = new Date(); | ||
String testSuite = System.getProperty("test"); | ||
return testSuite + " " + dateFormat.format(date); | ||
} | ||
|
||
|
||
public static Integer createNewSet(List<Integer> testIDs) | ||
{ | ||
Response response = PractiTestAPI.sendCreateTestSet(getNameForNewRun(), testIDs); | ||
return PractiTestAPI.sendCreateTestSet(getNameForNewRun(), testIDs).getBody().jsonPath().get("data.id") ; | ||
} | ||
|
||
public static Integer createNewInstance(Integer setID, Integer testID) | ||
{ | ||
return PractiTestAPI.sendCreateInstance(setID, testID).getBody().jsonPath().get("data.id"); | ||
} | ||
|
||
public static Integer submitResults(Integer instanceID, List<StepModel> stepModel) | ||
{ | ||
return PractiTestAPI.sendCreateRun(instanceID, stepModel).getBody().jsonPath().get("get.id"); | ||
|
||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
api.v2/java.v2/src/main/java/com/practitest/integration/ExtractTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.practitest.integration; | ||
|
||
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<Integer> extractAllTestIds(ITestContext context) | ||
{ | ||
ITestNGMethod[] testMethods = context.getAllTestMethods(); | ||
List<String> testIds = new ArrayList(0); | ||
for (ITestNGMethod testMethod : testMethods) { | ||
testIds.add(testMethod.getDescription()); | ||
} | ||
return testIds.stream().map(Integer::parseInt).collect(Collectors.toList()); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
api.v2/java.v2/src/main/java/com/webdriver/example/DriverFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<WebDriver> 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); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure i understand the logic here. Are you going to create a new TestSet every time 'mvn test' runs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand TestSet this is collection of tests which should be executed.
For example if you specify certain test for execution you'll need new TestSet in Practitest to store results for it. Correct me if I'm wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You right, TestSet is a collection of Tests. But subsequent executions are supposed to reuse existing TestSet.
Meaning that when you run your project first time, we should create the Tests and TestSet. When you run the project next time, we should use the TestSet created during first run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the time automated and manual tests are grouped to Smoke and Regression test suites or by some other project specific definition.
This means we should have multiple TestSets for them. Including test automation process into consideration we will have only some part automated at the start and number of automated != manual test cases. From this perspective it seam to me logical to create new TestSet each time as collection of tests most of the time will be different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add validation to reuse test set if collection of tests already exist for this group. Please let me know if this will work for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we should reuse testsets. If tests are added or removed, we should change the existing testset.