是否在Fire fox浏览器49.0版本中不支持selenium Standalone server 2.50?

时间:2016-11-07 09:59:17

标签: java eclipse selenium selenium-webdriver

selenium不支持最新的mozilla版本,有什么解决方案吗?

这是我的代码

package Admin_Package;

import org.openqa.selenium.WebDriver; import
org.openqa.selenium.firefox.FirefoxDriver;

public class test {



public static void main(String[] args) throws InterruptedException {
    // Download "geckodriver.exe" from https://github.com/mozilla/geckodriver/releases
    System.setProperty("webdriver.gecko.driver","D:\\ecl_ee\\jar_files\\gecko_driver\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();

    driver.get("http://www.facebook.com");

    System.out.println("Application title is ============="+driver.getTitle());

    driver.quit();
} }
     

如果我在下面使用3.0.1独立提及错误       java.lang.IllegalStateException:驱动程序可执行文件不存在:D:\ ecl_ee \ jar_files \ gecko_driver \ geckodriver.exe         在com.google.common.base.Preconditions.checkState(Preconditions.java:199)         在org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:121)         在org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:116)         在org.openqa.selenium.firefox.GeckoDriverService.access $ 000(GeckoDriverService.java:37)         在org.openqa.selenium.firefox.GeckoDriverService $ Builder.findDefaultExecutable(GeckoDriverService.java:95)         在org.openqa.selenium.remote.service.DriverService $ Builder.build(DriverService.java:296)         在org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:277)         在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:247)         在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:242)         在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:135)         在Admin_Package.test.before(test.java:20)         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:86)         at org.testng.internal.Invoker.invokeMethod(Invoker.java:646)         在org.testng.internal.Invoker.invokeTestMethod(Invoker.java:823)         at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)         at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)         在org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)         在org.testng.TestRunner.privateRun(TestRunner.java:778)         在org.testng.TestRunner.run(TestRunner.java:632)         在org.testng.SuiteRunner.runTest(SuiteRunner.java:366)         at 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)         在org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)         at org.testng.TestNG.runSuitesSequentially(TestNG.java:1225)         在org.testng.TestNG.runSuites(TestNG.java:1075)         在org.testng.TestNG.run(TestNG.java:1047)         at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)         在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)         在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)

浏览器打开,然后出现此错误

1478585217132 geckodriver INFO    Listening on 127.0.0.1:42466
Nov 08, 2016 11:36:57 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1478585217594 mozprofile::profile INFO    Using profile path C:\Users\Divya\AppData\Local\Temp\rust_mozprofile.Xge4QjcxXLSu
1478585217596 geckodriver::marionette INFO    Starting browser C:\Program Files\Mozilla Firefox\firefox.exe
1478585217605 geckodriver::marionette INFO    Connecting to Marionette on localhost:2185
1478585219168 Marionette  INFO    Listening on port 2185
1478585221536 Marionette  INFO    startBrowser 2a9015b9-cac1-4641-839d-8f9279055519
Nov 08, 2016 11:37:01 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript warning: http://reventics.infoversity.in/app/services/sharedProperties.js, line 13: unreachable code after return statement
JavaScript warning: http://reventics.infoversity.in/app/services/sharedProperties.js, line 13: unreachable code after return statement
Application title is =============Reventics
[Child 1708] ###!!! ABORT: Aborting on channel error.: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp, line 2052
Nov 08, 2016 11:37:09 AM org.openqa.selenium.os.UnixProcess destroy
SEVERE: Unable to kill process with PID 6120

enter image description here

之前,套件类之后

package Admin_Package;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeSuite;
public class BA_Admin {
public static WebDriver driver;
@BeforeSuite
public void beforeSuite() throws InterruptedException {           
System.setProperty("webdriver.gecko.driver","D:\\ecl_ee\\jar_files\\gecko_driver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("URL");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
@AfterSuite     
public void afterSuite() throws Exception { 
driver.quit();
}
}

扩展课程

package Admin_Package;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Role_Add extends Admin_Package.BA_Admin{
@BeforeTest
public void login() throws InterruptedException {
driver.findElement(By.xpath(".//*[@id='txtUsername']")).sendKeys("venkatm");
Thread.sleep(5000);
driver.findElement(By.xpath(".//*[@id='txtPassword']")).sendKeys("Password@123");
Thread.sleep(5000);
driver.findElement(By.xpath("html/body/div[2]/div/form/div/div/div[2]/div/button[1]")).click();
Thread.sleep(5000);
System.out.println("Login Test Case Passed"); 
} 
@Test
public void link1() throws InterruptedException { 
driver.findElement(By.xpath("html/body/div[1]/aside/section/ul[1]/li[1]")).click();
Thread.sleep(5000);
}  
}
}

运行此类后,错误即将来临

1478588994124 geckodriver INFO    Listening on 127.0.0.1:36811
Nov 08, 2016 12:39:54 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1478588994625 mozprofile::profile INFO    Using profile path C:\Users\Divya\AppData\Local\Temp\rust_mozprofile.9LNcRBy7LvnX
1478588994628 geckodriver::marionette INFO    Starting browser C:\Program Files\Mozilla Firefox\firefox.exe
1478588994637 geckodriver::marionette INFO    Connecting to Marionette on localhost:3453
1478588996301 Marionette  INFO    Listening on port 3453
1478588998908 Marionette  INFO    startBrowser 533a5574-8667-4d6a-8455-b78be6709d83
Nov 08, 2016 12:39:59 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript warning: http://reventics.infoversity.in/app/services/sharedProperties.js, line 13: unreachable code after return statement
JavaScript warning: http://reventics.infoversity.in/app/services/sharedProperties.js, line 13: unreachable code after return statement
[Utils] Attempting to create D:\ecl_ee\Projects\Reventics\test-output\Default suite\Default test.html
[Utils]   Directory D:\ecl_ee\Projects\Reventics\test-output\Default suite exists: true
[Utils] Attempting to create D:\ecl_ee\Projects\Reventics\test-output\Default suite\Default test.xml
[Utils]   Directory D:\ecl_ee\Projects\Reventics\test-output\Default suite exists: true
FAILED CONFIGURATION: @BeforeTest login
java.lang.NullPointerException
at Admin_Package.Role_Add.login(Role_Add.java:18)
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:86)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:216)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:143)
at org.testng.TestRunner.beforeRun(TestRunner.java:656)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.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:1225)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1150)
at org.testng.TestNG.runSuites(TestNG.java:1075)
at org.testng.TestNG.run(TestNG.java:1047)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)

SKIPPED CONFIGURATION: @AfterTest Create_Role
SKIPPED: link1

谢谢,

迪夫亚

1 个答案:

答案 0 :(得分:1)

creating a local variable is causing all the troubles.

WebDriver driver = new FirefoxDriver();

remove WebDriver reference in the object creation, so the reference will be added to the global driver object so that Child classes can refer.