簡體   English   中英

火狐硒網絡驅動程序中的錯誤

[英]Error in fire fox selenium web driver

最近,使用 selenium firefox 驅動程序遇到了這個問題。 提前致謝

設置

os.name: 'Mac OS X',

os.arch: 'x86_64',

操作系統版本:'10.12.6',

java.version: '1.8.0_131'

Firefox 版本56.0.1(64 位)

Gecko 驅動程序最新 0.19.0

錯誤顯示 failed: 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

你的問題在這里:

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

僅嘗試使用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