失败的配置:@BeforeClass setUp和FAILED CONFIGURATION:@AfterClass tearDown java.lang.NullPointerException errors

时间:2016-10-14 10:25:41

标签: java eclipse maven selenium-webdriver geckodriver

我使用的是selenium 3.0.0-beta4版本。试图在我的项目上配置geckoDriver的设置。我使用Maven和TestNG以及java。

import java.util.concurrent.TimeUnit;
import org.testng.annotations.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.WebDriver;

public class GmailSignupAutomation {
    private WebDriver driver;
      private String baseUrl;

 @BeforeClass(alwaysRun = true)
      public void setUp() throws Exception {System.setProperty("webdriver.gecko.driver","D://software_/geckodriver-v0.11.1-win64/geckodriver.exe");

      DesiredCapabilities capabilities = DesiredCapabilities.firefox();
      capabilities.setCapability("marionette", true);
      **driver = new FirefoxDriver(capabilities);**

        baseUrl = "https://accounts.google.com/";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      }

@Test
      public void testGoogleAccountLoginForm() throws Exception {
        driver.get(baseUrl + "//SignUp?service=mail&continue=https://mail.google.com/mail/?pc=topnav-about-en");
        driver.findElement(By.id("FirstName")).clear();
        driver.findElement(By.id("FirstName")).sendKeys("HOSSAIN");
      }

@AfterClass(alwaysRun = true)
      public void tearDown() throws Exception {
        driver.quit();
      }

}

这是输出:

1476438749160 geckodriver INFO在127.0.0.1:39530 Oct 14,2016 3:52:29 PM org.openqa.selenium.remote.ProtocolHandshake createSession

信息:尝试双方会话,假设Postel的法律在远程端是正确的

1476438749613 mozprofile :: profile INFO使用配置文件路径C:\ Users \ HOSSAI~1.MAH \ AppData \ Local \ Temp \ rust_mozprofile.e9aWwalq9rWK

1476438749656 geckodriver :: marionette INFO启动浏览器C:\ Program Files \ Mozilla Firefox \ firefox.exe

1476438749683 geckodriver :: marionette INFO在本地主机上连接到木偶:61519 Oct 14,2016 3:52:32 PM org.openqa.selenium.remote.ProtocolHandshake createSession

信息:退回直接W3C远程终端连接

1476438752490 mozprofile :: profile INFO使用配置文件路径C:\ Users \ HOSSAI~1.MAH \ AppData \ Local \ Temp \ rust_mozprofile.D6FkME6daU3V

1476438752499 geckodriver :: marionette INFO启动浏览器C:\ Program Files \ Mozilla Firefox \ firefox.exe

1476438752535 geckodriver :: marionette INFO在本地主机上连接到木偶:61527 2016年10月14日下午3:52:37 org.openqa.selenium.remote.ProtocolHandshake createSession

信息:回归原始OSS JSON有线协议。 1476438757062 mozprofile :: profile INFO使用个人资料路径

C:\用户\ HOSSAI〜1.MAH \应用程序数据\本地\ TEMP \ rust_mozprofile.FHKHmYIM3lXI

1476438757069 geckodriver :: marionette INFO启动浏览器C:\ Program Files \ Mozilla Firefox \ firefox.exe

1476438757127 geckodriver :: marionette INFO通过localhost连接到Marionette:61557

[Utils]尝试创建D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ Default suite \ Default test.xml

[Utils]目录D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \默认套件存在:true

FAILED CONFIGURATION:@BeforeClass setUp org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。 desired capabilities = Capabilities [{marionette = true,browserName = firefox,version =,platform = ANY}],required capabilities = Capabilities [{}]

构建信息:版本:'未知',修订版:' 3169782',时间:' 2016-09-29 10:24:50 -0700'系统信息:主机:' XYZ',ip:' 101.140.178.123',os.name:' Windows 7',os.arch:' amd64',os.version:' 6.1',java.version:' 1.8.0_102'

驱动程序信息:driver.version:Firefox驱动程序位于org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:80)org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)at at Org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:602)org.openqa.selenium.remote.RemoteWebDriver。 startGession(RemoteWebDriver.java:242)org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:129)org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:247)org.openqa.selenium .firefox.FirefoxDriver。(FirefoxDriver.java:235)org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:230)org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:226)at org SeleniumAutomation.GoogleSignupAutomation.GmailSig上的.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:124) nupAutomation.setUp(GmailSignupAutomation.java:39)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)at java.lang位于org.testng.internal的org.testng.internal.invokeMinod(Invoke.java:515)的org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)的.reflect.Method.invoke(未知来源) .invoker.invokeConfigurations(Invoker.java:216)org.testng.internal.InvokeConfigurations(Invoker.java:143)org.testng.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:169)org.testng的org.testng.internal.Invoker.invokeConfigurations(Invoker.java:143)。 org.testng.SuiteRunner.runTest上的org.testng.TestRunner.run(TestRunner.java:600)org.testng.TestRunner.privateRun(TestRunner.java:746)中的internal.TestMethodWorker.run(TestMethodWorker.java:108) (SuiteRunner.java:366)org.testng.SuiteRunner.run顺序(SuiteRunner.java:361)org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)org.testng.SuiteRunner.run(SuiteRunner.java:268)org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java: 52)org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)org.testng.TestNG.runSuitesSequentially(TestNG.java:1264)atg.testng.TestNG.runSuitesLocally(TestNG.java:1189)at org。 org.testng.remun.TunN.RunSuites(TestNG.java:1104)org.testng.TestNG.run(TestNG.java:1076)org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)org.testng.remote上的testng.TestNG.runSuites(TestNG.java:1104) .RemoteTestNG.initAndRun(RemoteTestNG.java:152)org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)

FAILED CONFIGURATION:@AfterClass tearDown java.lang.NullPointerException at SeleniumAutomation.GoogleSignupAutomation.GmailSignupAutomation.tearDown(GmailSignupAutomation.java:55)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(来自org.testng的org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)的java.lang.reflect.Method.invoke(未知来源)的sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)的未知来源.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)org.testng.internal.Invoker.invokeConfigurations(Invoker.java:216)at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:143)at org。在org.testng的org.testng.TestRunner.privateRun(TestRunner.java:746)的org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:115)上的testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:217) .TestRunner。运行(TestRunner.java:600)org.testng.SuiteRunner.runTest(SuiteRunner.java:366)atg.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)org.testng.SuiteRunner.privateRun(SuiteRunner.java) :319)org.testng.SuiteRunner.run(SuiteRunner.java:268)org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)atg.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)at org 。orng.TestNG.runSuitesSequentially(TestNG.java:1264)org.testng.TestNG.runSuitesLocally(TestNG.java:1189)org.testng.TestNG.runSuites(TestNG.java:1104)atg.testng.TestNG。运行(TestNG.java:1076)org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)atg.testng.remote.RemoteTestNG 。主要(RemoteTestNG.java:57)

SKIPPED:testGoogleAccountLoginForm

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

配置失败:2,跳过:0

===============================================默认套件总测试运行:1,失败:0,跳过:1配置失败:2,跳过:0

[TestNG] org.testng.reporters.XMLReporter@3b938003所花费的时间:50 ms [TestNG] org.testng.reporters.EmailableReporter2@475e586c所花费的时间:12 ms [Utils]试图创建D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \ Default suite \ toc.html [Utils]目录D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \默认套件存在:true [Utils]试图创建D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \默认套件\默认test.properties [Utils]目录D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \默认套件存在:true [Utils]尝试创建D: \ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \ Default suite \ index.html [Utils]目录D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \默认套件存在:true [Utils]尝试创建D :\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \ Default suite \ main.html [Utils]目录D:\ Projects \ Automation \ Go ogleSignupAutomation \ test-output \ old \默认套件存在:true [Utils]尝试创建D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \ Default suite \ groups.html [Utils]目录D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \默认套件存在:true [Utils]尝试创建D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \ Default suite \ classes.html [Utils]目录D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \默认套件存在:true [Utils]尝试创建D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \ Default suite \ reporter-output.html [Utils]目录D: \ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \默认套件存在:true [Utils]尝试创建D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \ Default suite \ methods-not-run.html [实用工具]目录D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \默认套件存在:true [Utils] Attem pting创建D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \ Default suite \ testng.xml.html [Utils]目录D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \默认套件存在:true [Utils]试图创建D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old \ index.html [Utils]目录D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ old exists:true [TestNG]所用时间by org.testng.reporters.SuiteHTMLReporter@780cb77:95 ms [Utils]试图创建D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ junitreports \ TEST-SeleniumAutomation.GoogleSignupAutomation.GmailSignupAutomation.xml [Utils]目录D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ junitreports存在:true [TestNG] org.testng.reporters.JUnitReportReporter@3a079870所占用的时间:106 ms [TestNG] org.testng.reporters.jq.Main@17c1bced所用的时间: 241 ms [Utils]试图创建D:\ Projects \ Automation \ GoogleSignupAutomation \ test-ou tput \ testng-failed.xml [Utils]目录D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output exists:true [Utils]尝试创建D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \ Default suite \ testng- failed.xml [Utils]目录D:\ Projects \ Automation \ GoogleSignupAutomation \ test-output \默认套件存在:true [TestNG] [FailedReporter传递= 0失败= 0跳过= 0]所花费的时间:8毫秒

2 个答案:

答案 0 :(得分:1)

我认为在设置驱动程序路径后,您需要将DesiredCapabilities设置为MarionetteDriver,如下面的代码所示。对我有用。

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
                            capabilities.setCapability("marionette", true);
                            Driver = new MarionetteDriver(capabilities);

答案 1 :(得分:1)

您可以尝试以下步骤:

  1. 下载牵线木偶驱动程序
  2. 将其归档到您选择的文件夹
  3. 在您的代码中将“webdriver.gecko.driver”属性设置为.exe
  4. 的位置
  5. 使用MarionetteDriver
  6. 将文件重命名为'wires.exe'和 将它添加到您的路径中。
  7. 我确实将它重命名为wires.exe,主要是为了保持代码的一致性,所以每次更改牵线木偶驱动程序的版本时都不需要更新代码。

    但我没有把它添加到路径中。当提供选项时,我宁愿在代码中控制它。

    Firefox 47及以上我的代码如下所示:

    String currentDir = System.getProperty("user.dir");
    String marionetteDriverLocation = currentDir + "/tools/marionette/wires.exe";
    System.setProperty("webdriver.gecko.driver", marionetteDriverLocation);
    WebDriver driver = new MarionetteDriver();
    

    您可以从以下github示例代码中检查代码更新:https://github.com/kumrunnaharkeya/sample-automation-selenium