您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium啟動firefox、ie、chrome各瀏覽器方法
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2016/1/25 11:20:37 ] 推薦標簽:軟件測試工具 功能測試工具

  1、啟動firefox瀏覽器
  a.如果你的本地firefox是默認路徑安裝的話,如下方式即可啟動瀏覽器
  WebDriver driver = new FirefoxDriver();
  driver.get("http://www.baidu.com");
  b.如果不是默認路徑安裝,需要先將firefox.exe配置到系統(tǒng)變量中去,如下:
  System.setProperty("webdriver.firefox.bin", "D:\ruanjian\Firefox\azml\firefox.exe");
  driver = new FirefoxDriver();
  String url = "http://www.baidu.com";
  driver.get(url);
  2、啟動ie瀏覽器,由于ie,chrome瀏覽器的driverServer是由他們自己管理的,我們需要下載相應(yīng)的驅(qū)動,注意區(qū)分 32位和64位,使用方法如下:
  System.setProperty("webdriver.ie.driver", "src\main\resources\IEDriver.exe");
  WebDriver driver = new InternetExplorerDriver();
  driver.get("http://www.baidu.com");
  同樣,如果ie不是默認路徑安裝需要配置bin路徑到系統(tǒng)屬性中去
  Tip:加載IEDriverServer的時候,通常會因為兼容模式的設(shè)置問題,而無法啟動,嘗試在創(chuàng)建IEDriver對象的時候 加入合適的參數(shù)設(shè)置:
  DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
  ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
  WebDriver driver = new InternetExplorerDriver(ieCapabilities);
  3、啟動chrome瀏覽器,需要下載chromedriver驅(qū)動
  System.setProperty("webdriver.chrome.driver","C:\Program Files (x86)\Google\Chrome\Application\chromedriver_x64.exe");
  WebDriver driver = new ChromeDriver();
  driver.get("http://www.baidu.com");
  4、啟動瀏覽器的過程中,經(jīng)常出現(xiàn)啟動瀏覽器窗口,卻沒有完成輸入url地址的情況,大部分由于版本不兼容造成的。
  比如:火狐的會報如下錯誤
  org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.

軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd