首页 > 编程语言 > 详细

Selenium +java+webdriver 启动各浏览器

时间:2015-03-13 18:58:20      阅读:431      评论:0      收藏:0      [点我收藏+]

http://www.seleniumhq.org/  selenium启动各浏览器程序

下载最新程序

 

启动IE浏览器:

import org.openqa.selenium.*;

importorg.openqa.selenium.ie.InternetExplorerDriver;

System.setProperty("webdriver.ie.driver","C:\\testdriver\\IEDriverServer.exe");

DesiredCapabilities ieCapabilities =DesiredCapabilities.internetExplorer();   

ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);  

WebDriver IEWebDriver = newInternetExplorerDriver(ieCapabilities);

IEWebDriver.get("http://www.baidu.com");

启动firefox浏览器:

importorg.openqa.selenium.firefox.FirefoxDriver;

importorg.openqa.selenium.firefox.FirefoxProfile;

FirefoxProfile profile = newFirefoxProfile();

profile.setPreference("general.useragent.override","Mozilla/5.0(iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML,like Gecko) Version/4.0 Mobile/7A341 Safari/528.16");

System.setProperty("webdriver.firefox.bin","C:\\ProgramFiles (x86)\\Mozilla Firefox\\firefox.exe");

WebDriver mdriver = newFirefoxDriver(profile);

启动google浏览器:

importorg.openqa.selenium.WebDriver;

importorg.openqa.selenium.chrome.ChromeDriver;

System.setProperty("webdriver.chrome.driver","C:\\testdriver\\chromedriver.exe");

WebDriver driver = newChromeDriver();

启动HtmlUnitDriver.(html unitDriver 内存运行是不支持截图功能的哦

importorg.openqa.selenium.htmlunit.HtmlUnitDriver;

driver = new HtmlUnitDriver();

 

本文出自 “软件测试” 博客,谢绝转载!

Selenium +java+webdriver 启动各浏览器

原文:http://chineseliubo.blog.51cto.com/3683952/1620163

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!