Selenium2測試腳本怎樣配置不一樣的瀏覽器

1、 谷歌瀏覽器配置html

當谷歌瀏覽器打不開,則要下載驅程chromedriver.exe,再添加setProperty,具體參數寫法參考如下:java

       //chromegit

  System.setProperty("webdriver.chrome.driver","D:/Program Files (x86)/webdriver/chromedriver.exe");github

        driver = new ChromeDriver();web

谷歌驅程下載地址:chrome

https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver
https://chromedriver.storage.googleapis.com/index.htmlapi

 

2、             火狐瀏覽器配置瀏覽器

當使用火狐瀏覽器,運行代碼,報如下錯誤:session

org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: WIN8_1app

Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'

System info: host: 'pengo', ip: '192.168.64.1', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_102'

Driver info: driver.version: FirefoxDriver

解決方法:

也是要下載驅程firefox.exe,再添加setProperty,具體參數寫法參考如下

//firefox

       System.setProperty("webdriver.firefox.bin","D:/Program Files (x86)/Mozilla Firefox/firefox.exe"); 

    driver = new FirefoxDriver();

火狐驅程下載地址:https://github.com/mozilla/geckodriver

 

3、             IE瀏覽器配置

一、當使用IE瀏覽器,運行代碼,報如下錯誤:

java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html

即要下載驅程IEDriverServer.exe,再添加setProperty,具體參數寫法參考如下:

    System.setProperty("webdriver.ie.driver","D:\\Program Files (x86)\\webdriver\\IEDriverServer.exe");

IE驅程下載地址:

https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver

http://selenium-release.storage.googleapis.com/index.html

 

二、當使用IE瀏覽器,運行代碼,報如下錯誤:

    org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}], required capabilities = Capabilities [{}]

即要添加setCapability,具體參數寫法參考如下:

        DesiredCapabilities capab = DesiredCapabilities.internetExplorer();

       capab.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);

      capab.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

       driver = new InternetExplorerDriver(capab);

三、selenium自動化測試中,有些IE瀏覽器輸入英文和數字會特別慢,大大下降了自動化測試的執行速度。此問題通常出如今64位Windows系統中。 解決方法: 將"IEDriverServer.exe​"從64位版本變爲32位版本。

相關文章
相關標籤/搜索