最近,使用selenium firefox驱动程序遇到了这个问题。 提前致谢
设置
os.name:&& 39; Mac OS X',
os.arch:' x86_64',
os.version:' 10.12.6',
java.version:' 1.8.0_131'
Firefox版本 56.0.1(64位)
Gecko驱动程序 最新0.19.0
错误显示失败: org.openqa.selenium.SessionNotCreatedException:试图运行命令 没有建立连接
我尝试了不同的方法来解决它,但总是会出现同样的错误。 1.将所有selenium测试驱动程序更新到最新版本 2.指定目录export PATH = $ PATH driverDir
我的代码
package automationFramework;
import org.apache.commons.io.FileUtils;
import org.junit.*;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.safari.SafariDriver;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
public class GeckoDriver {
private static WebDriver driver;
public static int random = 0;
private String baseURL;
// @BeforeClass : Executes only once for the Test-Class.
@BeforeClass
public static void setting_SystemProperties(){
System.out.println("System Properties seting Key value.");
}
// @Before : To execute once before ever Test.
@Before
public void test_Setup(){
System.out.println("Launching Browser");
if (random == 0) {
System.out.println("Start Chrome Browser Testing ");
System.setProperty("webdriver.gecko.driver", "/Users/Fannity/Desktop/Drivers/geckodriver"); // Chrome Driver Location.
driver = new FirefoxDriver();
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
System.out.println("Session ID : " + ((RemoteWebDriver) driver).getSessionId() );
}
@Test
public void selenium_ScreenShot() throws IOException {
baseURL = "https://www.google.com/";
driver.get(baseURL);
System.out.println("Selenium Screen shot.");
File screenshotFile = ((RemoteWebDriver) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshotFile, new File("/Users/Fannity/Desktop/JUNIT-Selenium.jpg"));
random += 1;
}
// @After : To execute once after ever Test.
@After
public void test_Cleaning(){
System.out.println("Closing Browser");
baseURL = null;
driver.close();
driver.quit();
}
// @AfterClass : Executes only once before Terminating the Test-Class.
@AfterClass
public static void clearing_SystemProperties(){
System.out.println("System Property Removing Key value.");
System.clearProperty("webdriver.gecko.driver");
}
}
错误
https://gist.github.com/Fenici/f82f885486de37ae110fda8d7430df6e
答案 0 :(得分:2)
你的问题在这里:
@After
public void test_Cleaning(){
System.out.println("Closing Browser");
baseURL = null;
driver.close();
driver.quit();
}
只能使用close()
。
Here解释得非常好。