Skip to content

Commit e55fa11

Browse files
committed
initial, testng examples
0 parents  commit e55fa11

File tree

10 files changed

+350
-0
lines changed

10 files changed

+350
-0
lines changed

Diff for: extentreports-testng-adapter-example/.gitignore

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.nar
17+
*.ear
18+
*.zip
19+
*.tar.gz
20+
*.rar
21+
22+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23+
hs_err_pid*
24+
25+
# eclipse
26+
.classpath
27+
.project
28+
29+
target/
30+
test-output/
31+
.idea/
32+
*.iml
33+
.settings/

Diff for: extentreports-testng-adapter-example/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 aventstack
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: extentreports-testng-adapter-example/Readme.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## extentreports-testng-adapter-example
2+
3+
View `src/test/` for examples.
4+
5+
### Bugs and Feature requests
6+
7+
You can register bugs and feature requests in the [Github Issue Tracker](https://github.com/extent-framework/extentreports-testng-adapter/issues).
8+
9+
### License
10+
11+
MIT

Diff for: extentreports-testng-adapter-example/pom.xml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.aventstack</groupId>
7+
<artifactId>extentreports-testng-adapter-example</artifactId>
8+
<version>1.0.0</version>
9+
<name>extentreports-testng-adapter-example</name>
10+
<url>http://extentreports.com</url>
11+
<description>Extent Framework and TestNG integration example using the extentreports-testng-adapter-example</description>
12+
13+
<scm>
14+
<connection>scm:git:https://github.com/extent-framework/extentreports-testng-adapter-example.git</connection>
15+
<developerConnection>scm:git:https://github.com/extent-framework/extentreports-testng-adapter-example.git</developerConnection>
16+
<url>https://github.com/extent-framework/extentreports-testng-adapter-example</url>
17+
</scm>
18+
19+
<licenses>
20+
<license>
21+
<name>The MIT License</name>
22+
<url>https://opensource.org/licenses/MIT</url>
23+
</license>
24+
</licenses>
25+
26+
<developers>
27+
<developer>
28+
<name>Anshoo Arora</name>
29+
<url>https://github.com/anshooarora</url>
30+
<id>anshoo.arora</id>
31+
<roles>
32+
<role>Owner</role>
33+
</roles>
34+
</developer>
35+
</developers>
36+
37+
<properties>
38+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
39+
</properties>
40+
41+
<dependencies>
42+
<!-- <dependency>
43+
<groupId>com.aventstack</groupId>
44+
<artifactId>extentreports-testng-adapter</artifactId>
45+
<version>1.0.2</version>
46+
</dependency>-->
47+
<dependency>
48+
<groupId>com.aventstack</groupId>
49+
<artifactId>extentreports</artifactId>
50+
<version>4.0.1</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.testng</groupId>
54+
<artifactId>testng</artifactId>
55+
<version>6.9.10</version>
56+
</dependency>
57+
</dependencies>
58+
59+
<build>
60+
<plugins>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-compiler-plugin</artifactId>
64+
<version>2.3.2</version>
65+
<configuration>
66+
<source>1.8</source>
67+
<target>1.8</target>
68+
</configuration>
69+
</plugin>
70+
<plugin>
71+
<groupId>org.apache.maven.plugins</groupId>
72+
<artifactId>maven-resources-plugin</artifactId>
73+
<version>2.7</version>
74+
</plugin>
75+
</plugins>
76+
</build>
77+
78+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.aventstack.extentreports.adapter.testng.tests;
2+
3+
import org.testng.Assert;
4+
import org.testng.ITestResult;
5+
import org.testng.annotations.AfterMethod;
6+
import org.testng.annotations.DataProvider;
7+
import org.testng.annotations.Listeners;
8+
import org.testng.annotations.Test;
9+
10+
import com.aventstack.extentreports.service.ExtentTestManager;
11+
import com.aventstack.extentreports.testng.listener.ExtentITestListenerClassAdapter;
12+
13+
@Listeners({ ExtentITestListenerClassAdapter.class })
14+
public class DataProviderTests {
15+
16+
@DataProvider(name = "Authentication")
17+
public static Object[][] credentials() {
18+
return new Object[][] { { "testuser_1", "Test@123" }, { "testuser_2", "Test@123" } };
19+
}
20+
21+
@Test(dataProvider = "Authentication", groups = { "ExtentFramework", "TestNG", "a:Anshoo", "d:iPhoneX" })
22+
public void passDataProviderTests(String user, String password) {
23+
Assert.assertTrue(true);
24+
}
25+
26+
@Test(dataProvider = "Authentication")
27+
public void failDataProviderTests(String user, String password) {
28+
Assert.assertTrue(false);
29+
}
30+
31+
@AfterMethod
32+
public synchronized void afterMethod(ITestResult result) {
33+
switch (result.getStatus()) {
34+
case ITestResult.FAILURE:
35+
ExtentTestManager.getTest(result).fail("ITestResult.FAILURE, event afterMethod");
36+
break;
37+
case ITestResult.SKIP:
38+
ExtentTestManager.getTest(result).skip("ITestResult.SKIP, event afterMethod");
39+
break;
40+
default:
41+
ExtentTestManager.getTest(result).pass("default, event afterMethod");
42+
break;
43+
}
44+
}
45+
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.aventstack.extentreports.adapter.testng.tests;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.nio.file.Files;
6+
7+
import org.testng.Assert;
8+
import org.testng.ITestResult;
9+
import org.testng.annotations.AfterMethod;
10+
import org.testng.annotations.Listeners;
11+
import org.testng.annotations.Test;
12+
13+
import com.aventstack.extentreports.MediaEntityBuilder;
14+
import com.aventstack.extentreports.service.ExtentTestManager;
15+
import com.aventstack.extentreports.testng.listener.ExtentITestListenerClassAdapter;
16+
17+
@Listeners({ExtentITestListenerClassAdapter.class})
18+
public class ScreenshotTests {
19+
20+
// A static image stored under classpath
21+
private static final String IMG_PATH = "src/test/resources/screenshot.png";
22+
23+
// Using the same OUTPUT_PATH as set in extent.properties [extent.reporter.html.out]
24+
private static final String OUTPUT_PATH = "test-output/HtmlReport/";
25+
26+
27+
@Test
28+
public void passTest() {
29+
Assert.assertTrue(true);
30+
}
31+
32+
/**
33+
* A screenshot will be attached for failTest
34+
*/
35+
@Test
36+
public void failTest() {
37+
Assert.assertTrue(false);
38+
}
39+
40+
@AfterMethod
41+
public synchronized void afterMethod(ITestResult result) throws IOException {
42+
switch (result.getStatus()) {
43+
case ITestResult.FAILURE:
44+
ExtentTestManager.getTest(result).fail(
45+
"ITestResult.FAILURE, event afterMethod",
46+
MediaEntityBuilder.createScreenCaptureFromPath(getImage()).build()
47+
);
48+
break;
49+
case ITestResult.SKIP:
50+
ExtentTestManager.getTest(result).skip("ITestResult.SKIP, event afterMethod");
51+
break;
52+
default:
53+
break;
54+
}
55+
}
56+
57+
/**
58+
* !!This code block is just an example only!!
59+
* !!Real-world implemention would require capturing a screenshot!!
60+
*
61+
* @return Image path
62+
* @throws IOException
63+
*/
64+
private String getImage() throws IOException {
65+
String sc = "screenshot.png";
66+
Files.copy(new File(IMG_PATH).toPath(), new File(OUTPUT_PATH + sc).toPath());
67+
return sc;
68+
}
69+
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.aventstack.extentreports.adapter.testng.tests;
2+
3+
import org.testng.Assert;
4+
import org.testng.annotations.Listeners;
5+
import org.testng.annotations.Test;
6+
7+
import com.aventstack.extentreports.testng.listener.ExtentITestListenerClassAdapter;
8+
9+
@Listeners({ExtentITestListenerClassAdapter.class})
10+
public class SimpleAssertTests {
11+
12+
@Test
13+
public void passTest() {
14+
Assert.assertTrue(true);
15+
}
16+
17+
@Test
18+
public void failTest() {
19+
Assert.assertTrue(false);
20+
}
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
extent.reporter.avent.start=false
2+
extent.reporter.bdd.start=false
3+
extent.reporter.cards.start=false
4+
extent.reporter.email.start=false
5+
extent.reporter.html.start=true
6+
extent.reporter.klov.start=false
7+
extent.reporter.logger.start=false
8+
extent.reporter.tabular.start=false
9+
10+
extent.reporter.avent.config=
11+
extent.reporter.bdd.config=
12+
extent.reporter.cards.config=
13+
extent.reporter.email.config=
14+
extent.reporter.html.config=src/test/resources/html-config.xml
15+
extent.reporter.klov.config=
16+
extent.reporter.logger.config=
17+
extent.reporter.tabular.config=
18+
19+
extent.reporter.avent.out=test-output/AventReport/
20+
extent.reporter.bdd.out=test-output/BddReport/
21+
extent.reporter.cards.out=test-output/CardsReport/
22+
extent.reporter.email.out=test-output/EmailReport/ExtentEmail.html
23+
extent.reporter.html.out=test-output/HtmlReport/ExtentHtml.html
24+
extent.reporter.logger.out=test-output/LoggerReport/
25+
extent.reporter.tabular.out=test-output/TabularReport/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<extentreports>
3+
<configuration>
4+
<!-- report theme -->
5+
<!-- standard, dark -->
6+
<theme>standard</theme>
7+
8+
<!-- document encoding -->
9+
<!-- defaults to UTF-8 -->
10+
<encoding>UTF-8</encoding>
11+
12+
<!-- enable or disable timeline on dashboard -->
13+
<enableTimeline>true</enableTimeline>
14+
15+
<!-- protocol for script and stylesheets -->
16+
<!-- defaults to https -->
17+
<protocol>https</protocol>
18+
19+
<!-- title of the document -->
20+
<documentTitle>Extent Framework and TestNG Integration Example</documentTitle>
21+
22+
<!-- report name - displayed at top-nav -->
23+
<reportName>Examples</reportName>
24+
25+
<!-- create a report with all artifacts stored locally -->
26+
<enableOfflineMode>true</enableOfflineMode>
27+
28+
<!-- custom javascript -->
29+
<scripts>
30+
<![CDATA[
31+
$(document).ready(function() {
32+
33+
});
34+
]]>
35+
</scripts>
36+
37+
<!-- custom styles -->
38+
<styles>
39+
<![CDATA[
40+
41+
]]>
42+
</styles>
43+
</configuration>
44+
</extentreports>
Loading

0 commit comments

Comments
 (0)