gpt4 book ai didi

java - 配置失败: @AfterClass tear

转载 作者:行者123 更新时间:2023-12-02 06:17:03 26 4
gpt4 key购买 nike

我正在使用 selenium 2.39 和 Testng火狐浏览器版本26

下面是代码

   package Examples;

import java.util.concurrent.TimeUnit;

import org.junit.BeforeClass;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class Example2 {
public static WebDriver driver;
//String ddd;
// public Example2() {
// super();
// }

@BeforeClass
public void beforeClass()
{
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(60000, TimeUnit.MILLISECONDS);
}

@Test(dataProvider="Mail Information")
public void mailSend(String to,String subject,String body) throws Exception

{

driver.get("https://www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("xyzy@gmail.com");
driver.findElement(By.id("Passwd")).sendKeys("*********");
driver.findElement(By.id("signIn")).click();

driver.findElement(By.cssSelector("div[class='T-I J-J5-Ji T-I-KE L3']")).click();
driver.findElement(By.className("vO")).sendKeys(to);
driver.findElement(By.className("aoT")).sendKeys(subject);

driver.findElement(By.cssSelector(".editable")).click();
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@tabindex,'1') and contains(@frameborder,'0')]")));
driver.findElement(By.xpath("//body[@role='textbox']")).sendKeys(body);
driver.switchTo().defaultContent();
driver.findElement(By.cssSelector("div[class='T-I J-J5-Ji aoO T-I-atl L3']")).click();

driver.navigate().refresh();
}

@DataProvider (name = "Mail Information")
public Object[][] mailSendProvider()
{
return new Object[][]

{

{"xyzy@gmail.com","This is a Test Mail","hello"},
};

}

@AfterClass
public void tear()
{
driver.quit();
}
}

无法理解测试库的问题或 Testng 设置的问题

当 iam 使用 TestNG 运行时,我收到以下错误。

 [TestNG] Running:
C:\Users\Administrator\AppData\Local\Temp\testng-eclipse-1461140969\testng-customsuite.xml

FAILED CONFIGURATION: @AfterClass tear
java.lang.NullPointerException
at Examples.Example2.tear(Example2.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:225)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:114)
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.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

FAILED: mailSend("xyzy@gmail.com", "This is a Test Mail", "hello")
java.lang.NullPointerException
at Examples.Example2.mailSend(Example2.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
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.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)


===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@267b76: 34 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1ff3fcf: 145 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@1799a1e: 18 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 17 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@1ddcac5: 16 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@1d35bf2: 87 ms

有人可以帮我吗

最佳答案

注释“BeforeClass”是从 Junit 导入的,并且“AfterClass”是从 TestNg 导入的。

两者都是不同的 API,错误是由于引用“AfterClass”而没有从 TestNg 定义“BeforeClass”造成的。

请添加以下内容

import org.testng.annotations.BeforeClass; 

并删除以下内容

import org.junit.BeforeClass;

希望这有帮助

关于java - 配置失败: @AfterClass tear,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21359511/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com