简体   繁体   English

火狐硒网络驱动程序中的错误

[英]Error in fire fox selenium web driver

Recently, bump into this issues with selenium firefox driver.最近,使用 selenium firefox 驱动程序遇到了这个问题。 Thanks in advance提前致谢

Set UP设置

os.name: 'Mac OS X', os.name: 'Mac OS X',

os.arch: 'x86_64', os.arch: 'x86_64',

os.version: '10.12.6',操作系统版本:'10.12.6',

java.version: '1.8.0_131' java.version: '1.8.0_131'

Firefox version 56.0.1 (64-bit) Firefox 版本56.0.1(64 位)

Gecko Driver Latest 0.19.0 Gecko 驱动程序最新 0.19.0

The error shows failed: org.openqa.selenium.SessionNotCreatedException: Tried to run command without establishing a connection错误显示 failed: org.openqa.selenium.SessionNotCreatedException: 试图在未建立连接的情况下运行命令

I tried different ways to tackle it but always come with the same error.我尝试了不同的方法来解决它,但总是出现同样的错误。 1. update all the selenium test driver to the latest 2. specify the directory export PATH = $PATH driverDir 1. 更新所有 selenium 测试驱动到最新 2. 指定目录 export PATH = $PATH driverDir

My code我的代码

  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");
    }
}

ERROR错误

https://gist.github.com/Fenici/f82f885486de37ae110fda8d7430df6e https://gist.github.com/Fenici/f82f885486de37ae110fda8d7430df6e

Your problem is here:你的问题在这里:

@After
    public void test_Cleaning(){
        System.out.println("Closing Browser");
        baseURL = null;
        driver.close();
        driver.quit();
    }

Try only with close() .仅尝试使用close() Explanation here .在这里解释。

We generally get this , if we use driver.close() and driver.quit() together so it would be better if you remove driver.close() ;如果我们一起使用driver.close()driver.quit()我们通常会得到这个,所以如果你删除driver.close()会更好;

 public void test_Cleaning(){
        System.out.println("Closing Browser");
        baseURL = null;
        driver.quit();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM