【发布时间】:2017-02-23 18:02:37
【问题描述】:
我使用的是 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 Listening on 127.0.0.1:39530 Oct 14, 2016 3:52:29 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO:尝试双语会话,假设 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 Connecting to Marionette on localhost:61519 Oct 14, 2016 3:52:32 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO:回退到直接的 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 Connecting to Marionette on localhost:61527 Oct 14, 2016 3:52:37 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO:回退到原始 OSS JSON Wire 协议。 1476438757062 mozprofile::profile INFO 使用配置文件路径
C:\Users\HOSSAI~1.MAH\AppData\Local\Temp\rust_mozprofile.FHKHmYIM3lXI
1476438757069 geckodriver::marionette INFO 启动浏览器 C:\Program Files\Mozilla Firefox\firefox.exe
1476438757127 geckodriver::marionette INFO 连接到 localhost:61557 上的 Marionette
[Utils] 尝试创建 D:\Projects\Automation\GoogleSignupAutomation\test-output\Default suite\Default test.xml
[Utils] 目录 D:\Projects\Automation\GoogleSignupAutomation\test-output\Default 套件存在:true
配置失败:@BeforeClass 设置 org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。所需功能 = 功能 [{marionette=true, browserName=firefox, version=, platform=ANY}],所需功能 = 功能 [{}]
构建信息:版本:'未知',修订:'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: FirefoxDriver at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:80) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141) 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。 startSession(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) 在 org .openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:124) 在 SeleniumAutomation.GoogleSignupAutomation.GmailSig nupAutomation.setUp(GmailSignupAutomation.java:39) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 在 java.lang .reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515) at org.testng.internal .Invoker.invokeConfigurations(Invoker.java:216) 在 org.testng.internal.Invoker.invokeConfigurations(Invoker.java:143) 在 org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:169) 在 org.testng。 internal.TestMethodWorker.run(TestMethodWorker.java:108) at org.testng.TestRunner.privateRun(TestRunner.java:746) at org.testng.TestRunner.run(TestRunner.java:600) at org.testng.SuiteRunner.runTest (SuiteRunner.java:366) 在 org.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) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1264) at org.testng.TestNG.runSuitesLocally(TestNG.java:1189) at org. testng.TestNG.runSuites(TestNG.java:1104) at org.testng.TestNG.run(TestNG.java:1076) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126) at org.testng.remote .RemoteTestNG.initAndRun(RemoteTestNG.java:152) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)
配置失败:@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( 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:100) at org.testng .internal.Invoker.invokeConfigurationMethod(Invoker.java:515) 在 org.testng.internal.Invoker.invokeConfigurations(Invoker.java:216) 在 org.testng.internal.Invoker.invokeConfigurations(Invoker.java:143) 在 org. testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:217) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:115) at org.testng.TestRunner.privateRun(TestRunner.java:746) at org.testng .TestRunner。在 org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361) 在 org.testng.SuiteRunner.runTest(SuiteRunner.java:366) 在 org.testng.SuiteRunner.privateRun(SuiteRunner.java) 运行(TestRunner.java:600) :319) at org.testng.SuiteRunnerWorker.run(SuiteRunner.java:268) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org .testng.TestNG.runSuitesSequentially(TestNG.java:1264) 在 org.testng.TestNG.runSuitesLocally(TestNG.java:1189) 在 org.testng.TestNG.runSuites(TestNG.java:1104) 在 org.testng.TestNG。 run(TestNG.java:1076) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152) at org.testng.remote.RemoteTestNG .main(RemoteTestNG.java:57)
跳过:testGoogleAccountLoginForm
Default test
Tests run: 1, Failures: 0, Skips: 1
配置失败:2,跳过:0
================================================默认套件总测试运行:1,失败:0,跳过:1 配置失败:2,跳过:0
[TestNG] org.testng.reporters.XMLReporter@3b938003 花费的时间:50 毫秒 [TestNG] org.testng.reporters.EmailableReporter2@475e586c 花费的时间:12 毫秒 [Utils] 尝试创建 D:\Projects\ Automation\GoogleSignupAutomation\test-output\old\Default suite\toc.html [Utils] 目录 D:\Projects\Automation\GoogleSignupAutomation\test-output\old\Default suite exists: true [Utils] Attempting to create D:\Projects \Automation\GoogleSignupAutomation\test-output\old\Default suite\Default test.properties [Utils] 目录 D:\Projects\Automation\GoogleSignupAutomation\test-output\old\Default suite exists: true [Utils] Attempting to create D: \Projects\Automation\GoogleSignupAutomation\test-output\old\Default suite\index.html [Utils] Directory D:\Projects\Automation\GoogleSignupAutomation\test-output\old\Default suite exists: true [Utils] Attempting to create D :\Projects\Automation\GoogleSignupAutomation\test-output\old\Default suite\main.html [Utils] 目录 D:\Projects\Automation\Go ogleSignupAutomation\test-output\old\Default 套件存在:true [Utils] Attempting to create D:\Projects\Automation\GoogleSignupAutomation\test-output\old\Default suite\groups.html [Utils] 目录 D:\Projects\Automation \GoogleSignupAutomation\test-output\old\Default suite exists: true [Utils] Attempting to create D:\Projects\Automation\GoogleSignupAutomation\test-output\old\Default suite\classes.html [Utils] Directory D:\Projects\ Automation\GoogleSignupAutomation\test-output\old\Default 套件存在:true [Utils] 正在尝试创建 D:\Projects\Automation\GoogleSignupAutomation\test-output\old\Default suite\reporter-output.html [Utils] 目录 D: \Projects\Automation\GoogleSignupAutomation\test-output\old\Default 套件存在:true [Utils] Attempting to create D:\Projects\Automation\GoogleSignupAutomation\test-output\old\Default suite\methods-not-run.html [ Utils] 目录 D:\Projects\Automation\GoogleSignupAutomation\test-output\old\Default 套件存在:true [Utils] Attem点到创建 D:\Projects\Automation\GoogleSignupAutomation\test-output\old\Default suite\testng.xml.html [Utils] 目录 D:\Projects\Automation\GoogleSignupAutomation\test-output\old\Default 套件存在:true [Utils] 正在尝试创建 D:\Projects\Automation\GoogleSignupAutomation\test-output\old\index.html [Utils] 目录 D:\Projects\Automation\GoogleSignupAutomation\test-output\old 存在:true [TestNG] 所用时间由 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 毫秒 [TestNG] org.testng.reporters.jq.Main@17c1bced 花费的时间: 241 毫秒 [Utils] 尝试创建 D:\Projects\Automation\GoogleSignupAutomation\test-ou tput\testng-failed.xml [Utils] 目录 D:\Projects\Automation\GoogleSignupAutomation\test-output 存在:true [Utils] Attempting to create D:\Projects\Automation\GoogleSignupAutomation\test-output\Default suite\testng- failed.xml [Utils] 目录 D:\Projects\Automation\GoogleSignupAutomation\test-output\Default 套件存在:true [TestNG] [FailedReporter pass=0 failed=0 skipped=0] 所用时间:8 ms
【问题讨论】:
-
编辑了用于添加更新的编码部分。调试“driver = new FirefoxDriver(capabilities)”后发现:1.该步骤抛出Invoker.class 2.打开了3个firefox空白窗口
标签: java eclipse maven selenium-webdriver geckodriver