- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
I'm new to ExtentReports. I have gone through many videos in youtube to generate reports using ExtentReports with above titled conditions but didn't find the exact answer for which I was looking for.
When tried to execute multiple classes in a testng suite it says nullpointerexception For suppose just assume suite contains 3 classes(Test cases). For first class execution goes smoothly. Once it jumps to the second class it says NullPointerException. Below is my code
注意:也尝试过 @BeforeTest 和 @AfterTest...
public class AppInit {
public ExtentReports reports;
public ExtentTest testInfo;
public ExtentHtmlReporter htmlReporter;
@BeforeSuite
public void reportSetup() {
htmlReporter = new ExtentHtmlReporter(new File(System.getProperty("user.dir") + "/AutomationReports.html"));
htmlReporter.loadXMLConfig(new File(System.getProperty("user.dir") + "/src/resource/XML/Extent-Config.xml"));
reports = new ExtentReports();
htmlReporter.setAppendExisting(true);
reports.setSystemInfo("Environment", "Automation");
reports.attachReporter(htmlReporter);
}
@BeforeMethod
public void testMethodName(Method method) {
String testName = method.getName();
testInfo = reports.createTest(testName);
}
@AfterMethod
public void capture_TestStatus(ITestResult result) {
try {
if (result.getStatus() == ITestResult.SUCCESS) {
testInfo.log(Status.PASS, "Test method " + "'" + result.getName() + "'" + result.getStatus());
} else if (result.getStatus() == ITestResult.FAILURE) {
testInfo.log(Status.FAIL, "Test method " + "'" + result.getName() + "'" + result.getStatus());
testInfo.log(Status.FAIL, "Test error " + result.getThrowable());
} else if (result.getStatus() == ITestResult.SKIP) {
testInfo.log(Status.SKIP, "Test method " + "'" + result.getName() + "'" + result.getStatus());
}
} catch (Exception e) {
e.printStackTrace();
}
}
@AfterSuite
public void generateReport() {
reports.flush();
}
}
异常/错误
Mar 30, 2018 10:21:07 PM main.java.com.xxx.yyy.framework.LogTestListener log INFO: test.java.com.xxx.yyy.tests.modules.zzz.explore.Attributes#serialNumber starting Mar 30, 2018 10:21:21 PM main.java.com.xxx.yyy.framework.LogTestListener log INFO: test.java.com.xxx.yyy.tests.modules.zzz.explore.Attributes#serialNumber completed Mar 30, 2018 10:21:21 PM main.java.com.xxx.yyy.framework.LogTestListener log INFO: test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa#poolName starting Mar 30, 2018 10:21:21 PM main.java.com.xxx.yyy.framework.LogTestListener log INFO: test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa#poolName skipped Mar 30, 2018 10:21:21 PM main.java.com.xxx.yyy.framework.LogTestListener log INFO: test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa#poolUsable starting Mar 30, 2018 10:21:21 PM main.java.com.xxx.yyy.framework.LogTestListener log INFO: test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa#poolUsable skipped Tests run: 9, Failures: 1, Errors: 0, Skipped: 7, Time elapsed: 38.356 sec <<< FAILURE! - in TestSuite testMethodName(test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa) Time elapsed: 14.078 sec <<< FAILURE! java.lang.NullPointerException: null at main.java.com.xxx.yyy.framework.AppInit.testMethodName(AppInit.java:178) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213) at org.testng.internal.Invoker.invokeMethod(Invoker.java:653) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) at org.testng.TestRunner.privateRun(TestRunner.java:767) at org.testng.TestRunner.run(TestRunner.java:617) at org.testng.SuiteRunner.runTest(SuiteRunner.java:334) at org.testng.SuiteRunner.access$000(SuiteRunner.java:37) at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:368) at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748)
Results :
Failed tests:
test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa.testMethodName(test.java.com.xxx.yyy.tests.modules.zzz.explore.Capacity.aaa)
Run 1: aaa>AppInit.testMethodName:178 » NullPointer
Run 2: PASS
Tests run: 7, Failures: 1, Errors: 0, Skipped: 5
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 43.588 s
[INFO] Finished at: 2018-03-30T22:21:22+05:30
[INFO] Final Memory: 21M/259M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test(default-test) on project Framework: There are test failures. [ERROR] [ERROR] Please refer to C:\bbb\Project_Workspace\Framework\target\surefire-reports for the individual test results. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
在maven中执行单个TestNg套装(具有多个类)。套房看起来像这样
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="ReportLibrary_Inventory_Test" parallel="tests">
<listeners>
<listener class-name="main.java.com.xxx.yyy.framework.LogTestListener"/>
</listeners>
<parameter name="browser" value="firefox" />
<parameter name="sUsername" value="aaa" />
<parameter name="sPassword" value="bbb" />
<test name="zzz_ReportLibrary_Inventory" enabled="true" preserve-order="true" group-by-instances="true">
<classes>
<class name="test.java.com.aaa.yyy.tests.modules.zzz.reportlibrary.inventory.ccc"></class>
<class name="test.java.com.aaa.yyy.tests.modules.zzz.reportlibrary.inventory.ddd"></class>
<class name="test.java.com.aaa.yyy.tests.modules.zzz.reportlibrary.inventory.eee"></class>
<!-- <class name="test.java.com.aaa.yyy.tests.modules.zzz.reportlibrary.inventory.Sample"></class> -->
<class name="test.java.com.aaa.yyy.tests.modules.zzz.reportlibrary.inventory.fff"></class>
<!-- <class name="test.java.com.aaa.yyy.tests.modules.zzz.reportlibrary.inventory.ggg"></class> -->
</classes>
</test>
</suite>
在maven(pom.xml)中执行多个testng套件
<suiteXmlFiles>
<!-- <suiteXmlFile>src/resource/TestNg_XML/zzz_ReportLibrary_Inventory.xml</suiteXmlFile> -->
<!-- <suiteXmlFile>src/resource/TestNg_XML/zzz_ReportLibrary_Summary_TableView.xml</suiteXmlFile> -->
<suiteXmlFile>src/resource/TestNg_XML/zzz_Explore_Attributes.xml</suiteXmlFile>
<!-- <suiteXmlFile>src/resource/TestNg_XML/zzz_All.xml</suiteXmlFile> -->
</suiteXmlFiles>
请帮我解决这个问题。我已经没有时间来交付了
提前致谢:)
Appint类代码
package main.java.com.xxx.zzz.framework;
import java.io.File;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.w3c.dom.Document;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import page.pageactions.LoginPageActions;
import page.pageactions.reportlibrarypageactions.ReportLibraryPageActions;
import test.java.com.xxx.zzz.tests.modules.centralizedManagement.Collecting;
import test.java.com.xxx.zzz.tests.modules.centralizedManagement.Modify_PollingInterval;
public class AppInit {
public static WebDriver driver;
public String convertStatus;
public String className;
public String testCase_MethodName;
public final static int Timer_Web_Element_Show = 30;
public static String retrievedUserEnteredbbbNamezzzUI;
public ExtentReports reports;
public ExtentTest testInfo;
public ExtentHtmlReporter htmlReporter;
// XML Parser
public static String resBodyXMLFilesPath;
public static File file;
public static DocumentBuilderFactory dbFactory;
public static DocumentBuilder dBuilder;
public static Document doc;
public static XPath xPath;
@BeforeSuite
public void reportSetup() {
htmlReporter = new ExtentHtmlReporter(new File(System.getProperty("user.dir") + "/AutomationReports.html"));
htmlReporter.loadXMLConfig(new File(System.getProperty("user.dir") + "/src/resource/XML/Extent-Config.xml"));
reports = new ExtentReports();
htmlReporter.setAppendExisting(true);
reports.setSystemInfo("Environment", "Automation");
reports.attachReporter(htmlReporter);
}
@BeforeSuite
@Parameters({ "browser", "sUsername", "sPassword" })
public void setup(String browser, String sUsername, String sPassword) throws Exception {
DataProviders.getPropertyData();
CommonMethods.deleteFilesFromDirectory("TestCaseResult_FolderPath");
// CommonMethods.deleteFilesFromDirectory("DownloadedFiles_Path");
// Check if parameter passed from TestNG is 'firefox'
if (browser.equalsIgnoreCase("firefox")) {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.dir",
CommonMethods.relativePath("", "\\src\\resource\\Downloaded_Files"));
profile.setPreference("browser.helperApps.neverAsk.openFile",
"application/log,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"application/log,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.closeWhenDone", false);
// create firefox instance
// System.setProperty("webdriver.firefox.marionette",
// ".\\geckodriver.exe");
driver = new FirefoxDriver(profile);
}
// Check if parameter passed as 'chrome'
else if (browser.equalsIgnoreCase("chrome")) {
// set path to chromedriver.exe
System.setProperty("webdriver.chrome.driver",
CommonMethods.relativePath("chromedriver.exe", "\\src\\lib\\"));
// create chrome instance
driver = new ChromeDriver();
} else {
// If no browser passed throw exception
throw new Exception("Browser is not correct");
}
driver.get(CommonMethods.dp_DataCollector("url"));
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
// Logging into zzz
LoginPageActions.username(sUsername);
LoginPageActions.password(sPassword);
LoginPageActions.loginButton();
Modify_PollingInterval.modify_TopologyPolling(); System.out.println(
"Topology polling executed successfully");
Modify_PollingInterval.modify_PerformancePolling();
System.out.println("Performance Polling executed successfully");
System.out.println("Modifying level and log file size started");
CommonMethods.ssh_ExecuteCommand("Collector_UserName",
"Collector_Password", "Collector_IP", "Collector_Port",
"sed -i 's/INFO/FINEST/g' /opt/APG/Collecting/Collector-Manager/yyy-aaa/conf/logging.properties && (>&2 echo 'Success') || (>&2 echo 'Fail')"
); CommonMethods.ssh_ExecuteCommand("Collector_UserName",
"Collector_Password", "Collector_IP", "Collector_Port",
"sed -i 's/1048576/1000048576/g' /opt/APG/Collecting/Collector-Manager/yyy-aaa/conf/logging.properties && (>&2 echo 'Success') || (>&2 echo 'Fail')"
); System.out.println("Modified level and log file size");
System.out.println("Re-Starting collector manager started");
CommonMethods.ssh_ExecuteCommand("Collector_UserName",
"Collector_Password", "Collector_IP", "Collector_Port",
"apg-collector-manager-yyy-aaa restart && (>&2 echo 'Success') || (>&2 echo 'Fail')"
); CommonMethods.pauseTime(8); System.out.println(
"Restarted collector manager");
System.out.println("Verifying one successful poll");
CommonMethods.polling_Check("Collector_UserName",
"Collector_Password", "Collector_IP", "Collector_Port");
System.out.println("One successful polling is done");
System.out.println("Downloading the log file");
CommonMethods.ssh_DownloadLogFile("Collector_UserName",
"Collector_Password", "Collector_IP", "Collector_Port");
System.out.println("Downloaded log file");
CommonMethods.get_ResponceBodyfromLog(CommonMethods.
retrieveLatestFileName_Downloaded().toString(),
"CreateNew_LogFile_aaa", "StartPoint_aaa", "EndPoint_aaa");
Collecting.dataBase_ImportPropertiesTask(); System.out.println(
"Property store executed successfully");
// Holding XML data in a doc for parsing it
resBodyXMLFilesPath = System.getProperty("user.dir") + CommonMethods.dp_DataCollector("CreateNew_LogFile_aaa");
file = new File(resBodyXMLFilesPath + ".xml");
dbFactory = DocumentBuilderFactory.newInstance();
dBuilder = dbFactory.newDocumentBuilder();
doc = dBuilder.parse(file);
doc.getDocumentElement().normalize();
xPath = XPathFactory.newInstance().newXPath();
retrievedUserEnteredbbbNamezzzUI = ReportLibraryPageActions.retrieveUserEnteredbbbName();
}
@BeforeMethod
public void testMethodName(Method method) {
String testName = method.getName();
testInfo = reports.createTest(testName);
}
@AfterMethod
public void capture_TestStatus(ITestResult result) {
try {
if (result.getStatus() == ITestResult.SUCCESS) {
testInfo.log(Status.PASS, "Test method " + "'" + result.getName() + "'" + result.getStatus());
} else if (result.getStatus() == ITestResult.FAILURE) {
testInfo.log(Status.FAIL, "Test method " + "'" + result.getName() + "'" + result.getStatus());
testInfo.log(Status.FAIL, "Test error " + result.getThrowable());
} else if (result.getStatus() == ITestResult.SKIP) {
testInfo.log(Status.SKIP, "Test method " + "'" + result.getName() + "'" + result.getStatus());
}
} catch (Exception e) {
e.printStackTrace();
}
}
@AfterSuite
public void generateReport() {
reports.flush();
}
@AfterSuite
public void tearDown() {
CommonMethods.pauseTime(5);
// reports.flush();
driver.quit();
}
}
按照建议修改代码
public class AppInit implements ISuiteListener, IInvokedMethodListener {
public void onStart(ISuite suite){
//Extent Reports
htmlReporter = new ExtentHtmlReporter(new File(System.getProperty("user.dir") + "/AutomationReports.html"));
htmlReporter.loadXMLConfig(new File(System.getProperty("user.dir") + "/src/resource/XML/Extent-Config.xml"));
reports = new ExtentReports();
htmlReporter.setAppendExisting(true);
reports.setSystemInfo("Environment", "Automation");
reports.attachReporter(htmlReporter);
DataProviders.getPropertyData();
CommonMethods.deleteFilesFromDirectory("TestCaseResult_FolderPath");
// CommonMethods.deleteFilesFromDirectory("DownloadedFiles_Path");
// Check if parameter passed from TestNG is 'firefox'
String getBrowserInput = suite.getParameter("browser");
if (getBrowserInput.equalsIgnoreCase("firefox")) {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.dir",
CommonMethods.relativePath("", "\\src\\resource\\Downloaded_Files"));
profile.setPreference("browser.helperApps.neverAsk.openFile",
"application/log,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"application/log,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.closeWhenDone", false);
// create firefox instance
// System.setProperty("webdriver.firefox.marionette",
// ".\\geckodriver.exe");
driver = new FirefoxDriver(profile);
}
// Check if parameter passed as 'chrome'
else if (getBrowserInput.equalsIgnoreCase("chrome")) {
// set path to chromedriver.exe
System.setProperty("webdriver.chrome.driver",
CommonMethods.relativePath("chromedriver.exe", "\\src\\lib\\"));
// create chrome instance
driver = new ChromeDriver();
} else {
// If no browser passed throw exception
try {
throw new Exception("Browser is not correct");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
driver.get(CommonMethods.dp_DataCollector("url"));
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
// Logging into aaa
String getUserName = suite.getParameter("sUsername");
String getPassword = suite.getParameter("sPassword");
LoginPageActions.username(getUserName);
LoginPageActions.password(getPassword);
LoginPageActions.loginButton();
resBodyXMLFilesPath = System.getProperty("user.dir") + CommonMethods.dp_DataCollector("CreateNew_LogFile_bbb");
file = new File(resBodyXMLFilesPath + ".xml");
dbFactory = DocumentBuilderFactory.newInstance();
try {
dBuilder = dbFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
doc = dBuilder.parse(file);
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
doc.getDocumentElement().normalize();
xPath = XPathFactory.newInstance().newXPath();
retrievedUserEnteredcccNameaaaUI = ReportLibraryPageActions.retrieveUserEnteredcccName();
}
public void onFinish(ISuite suite) {
CommonMethods.pauseTime(5);
reports.flush();
driver.quit();
}
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
String testName = method.getTestMethod().getMethodName();
testInfo = reports.createTest(testName);
}
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
if (testResult.getStatus() == ITestResult.SUCCESS) {
testInfo.log(Status.PASS, "Test method " + "'" + testResult.getName() + "'" + testResult.getStatus());
} else if (testResult.getStatus() == ITestResult.FAILURE) {
testInfo.log(Status.FAIL, "Test method " + "'" + testResult.getName() + "'" + testResult.getStatus());
testInfo.log(Status.FAIL, "Test error " + testResult.getThrowable());
} else if (testResult.getStatus() == ITestResult.SKIP) {
testInfo.log(Status.SKIP, "Test method " + "'" + testResult.getName() + "'" + testResult.getStatus());
}
}
}
删除监听器后的输出
[INFO] Scanning for projects... [INFO]
[INFO] ------------------------------------------------------------------------ [INFO] Building aaa 3.7-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ aaa --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 14 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ aaa --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ aaa --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory C:\zzz\bbb\aaa\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ aaa --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 13 source files to C:\zzz\bbb\aaa\target\test-classes [INFO] [INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ aaa --- [INFO] Surefire report directory: C:\zzz\bbb\aaa\target\surefire-reports------------------------------------------------------- T E S T S ------------------------------------------------------- Running TestSuite java.lang.NullPointerException at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210) at org.openqa.selenium.support.ui.FluentWait.(FluentWait.java:94) at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:70) at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:44) at page.pageactions.CommonMethodsPageActions.clickOnUI(CommonMethodsPageActions.java:24) at test.java.com.xxx.yyy.tests.modules.ccc_ddd.reportlibrary.inventory.eee.poolName(eee.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80) at org.testng.internal.Invoker.invokeMethod(Invoker.java:714) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) at org.testng.TestRunner.privateRun(TestRunner.java:767) at org.testng.TestRunner.run(TestRunner.java:617) at org.testng.SuiteRunner.runTest(SuiteRunner.java:334) at org.testng.SuiteRunner.access$000(SuiteRunner.java:37) at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:368) at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748) Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 4.799 sec <<< FAILURE! - in TestSuite diskName(test.java.com.xxx.yyy.tests.modules.ccc_ddd.reportlibrary.inventory.disks) Time elapsed: 2.071 sec <<< FAILURE! java.lang.NullPointerException: null at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210) at org.openqa.selenium.support.ui.FluentWait.(FluentWait.java:94) at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:70) at org.openqa.selenium.support.ui.WebDriverWait.(WebDriverWait.java:44) at page.pageactions.CommonMethodsPageActions.clickOnUI(CommonMethodsPageActions.java:24) at test.java.com.xxx.yyy.tests.modules.ccc_ddd.reportlibrary.inventory.disks.diskName(disks.java:21)
Results :
Failed tests: disks.diskName:21 » NullPointer
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 9.667 s [INFO] Finished at: 2018-04-03T18:47:16+05:30 [INFO] Final Memory: 21M/259M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project aaa: There are test failures. [ERROR] [ERROR] Please refer to C:\zzz\bbb\aaa\target\surefire-reports for the individual test results. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
最佳答案
问题在于您使用 @BeforeSuite
的方式和@BeforeTest
注释。
@BeforeSuite
/@AfterSuite
带注释的方法每个 <suite>
仅执行一次由 TestNG 标记。假设您的 <suite>
包含两个或多个 <test>
标签,即使这样 TestNG 也只会执行一次。
@BeforeSuite
/@AfterSuite
带注释的方法每个 <test>
仅执行一次由 TestNG 标记。假设您的 <test>
包含两个或多个类,即使这样 TestNG 也只会执行它们一次。
看起来你所有的测试类基本上都扩展了类 AppInit
.
所以仅适用于您的 <test>
中的第一个类@BeforeSuite
和@BeforeTest
将被执行。从第二个类开始,它将被跳过,即使第二个类也具有该方法作为继承的一部分。
您需要采用不同的机制来使用 ExtentReports
。我建议您使用 TestNG 监听器,其中构建一个实现 org.testng.ISuiteListener
的监听器并移动您的@BeforeSuite
/@AfterSuite
逻辑到此监听器中,并在同一实现中,让您的类也实现 org.testng.IInvokedMethodListener
并移动您的@BeforeMethod
/@AfterMethod
此实现中的逻辑。
最后,将此监听器连接到您的套件中。
关于java - 使用 ExtentReports 3.2 jar java 为一套测试服中的多个 testng 套装/类/多个套装生成报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49578543/
我获得了一些源代码示例,我想测试一些功能。不幸的是,我在执行程序时遇到问题: 11:41:31 [linqus@ottsrvafq1 example]$ javac -g test/test.jav
我想测试ggplot生成的两个图是否相同。一种选择是在绘图对象上使用all.equal,但我宁愿进行更艰巨的测试以确保它们相同,这似乎是identical()为我提供的东西。 但是,当我测试使用相同d
我确实使用 JUnit5 执行我的 Maven 测试,其中所有测试类都有 @ExtendWith({ProcessExtension.class}) 注释。如果是这种情况,此扩展必须根据特殊逻辑使测试
在开始使用 Node.js 开发有用的东西之前,您的流程是什么?您是否在 VowJS、Expresso 上创建测试?你使用 Selenium 测试吗?什么时候? 我有兴趣获得一个很好的工作流程来开发我
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 3 年前。 基于示例here ,我尝试为我的
我正在考虑测试一些 Vue.js 组件,作为 Laravel 应用程序的一部分。所以,我有一个在 Blade 模板中使用并生成 GET 的组件。在 mounted 期间请求生命周期钩子(Hook)。假
考虑以下程序: #include struct Test { int a; }; int main() { Test t=Test(); std::cout<
我目前的立场是:如果我使用 web 测试(在我的例子中可能是通过 VS.NET'08 测试工具和 WatiN)以及代码覆盖率和广泛的数据来彻底测试我的 ASP.NET 应用程序,我应该不需要编写单独的
我正在使用 C#、.NET 4.7 我有 3 个字符串,即。 [test.1, test.10, test.2] 我需要对它们进行排序以获得: test.1 test.2 test.10 我可能会得到
我有一个 ID 为“rv_list”的 RecyclerView。单击任何 RecyclerView 项目时,每个项目内都有一个可见的 id 为“star”的 View 。 我想用 expresso
我正在使用 Jest 和模拟器测试 Firebase 函数,尽管这些测试可能来自竞争条件。所谓 flakey,我的意思是有时它们会通过,有时不会,即使在同一台机器上也是如此。 测试和函数是用 Type
我在测试我与 typeahead.js ( https://github.com/angular-ui/bootstrap/blob/master/src/typeahead/typeahead.js
我正在尝试使用 Teamcity 自动运行测试,但似乎当代理编译项目时,它没有正确完成,因为当我运行运行测试之类的命令时,我收到以下错误: fatal error: 'Pushwoosh/PushNo
这是我第一次玩 cucumber ,还创建了一个测试和 API 的套件。我的问题是在测试 API 时是否需要运行它? 例如我脑子里有这个, 启动 express 服务器作为后台任务 然后当它启动时(我
我有我的主要应用程序项目,然后是我的测试的第二个项目。将所有类型的测试存储在该测试项目中是一种好的做法,还是应该将一些测试驻留在主应用程序项目中? 我应该在我的主项目中保留 POJO JUnit(测试
我正在努力弄清楚如何实现这个计数。模型是用户、测试、等级 用户 has_many 测试,测试 has_many 成绩。 每个等级都有一个计算分数(strong_pass、pass、fail、stron
我正在尝试测试一些涉及 OkHttp3 的下载代码,但不幸失败了。目标:测试 下载图像文件并验证其是否有效。平台:安卓。此代码可在生产环境中运行,但测试代码没有任何意义。 产品代码 class Fil
当我想为 iOS 运行 UI 测试时,我收到以下消息: SetUp : System.Exception : Unable to determine simulator version for X 堆
我正在使用 Firebase Remote Config 在 iOS 上设置 A/B 测试。 一切都已设置完毕,我正在 iOS 应用程序中读取服务器端默认值。 但是在多个模拟器上尝试,它们都读取了默认
[已编辑]:我已经用 promise 方式更改了我的代码。 我正在写 React with this starter 由 facebook 创建,我是测试方面的新手。 现在我有一个关于图像的组件,它有
我是一名优秀的程序员,十分优秀!