51Testing软件测试论坛
标题:
【转帖】WebDriver拾级而上(14) – RemoteWebDriver
[打印本页]
作者:
悠悠小仙仙
时间:
2017-7-14 11:54
标题:
【转帖】WebDriver拾级而上(14) – RemoteWebDriver
[attach]107450[/attach]
当本机上没有浏览器,需要远程调用浏览器进行自动化测试时,需要用到RemoteWebDirver.
一、使用RemoteWebDriver
CODE:
<font size="4">import java.io.File;
import java.net.URL;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.Augmenter;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class Testing {
public void myTest()throws Exception {
WebDriver driver = newRemoteWebDriver(
new URL("http://localhost:4446/wd/hub"),
DesiredCapabilities.firefox());
driver.get("http://www.google.com");
// RemoteWebDriverdoes not implement the TakesScreenshot class
// if the driver doeshave the Capabilities to take a screenshot
// then Augmenter willadd the TakesScreenshot methods to the instance
WebDriveraugmentedDriver = new Augmenter().augment(driver);
File screenshot =((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
}
}</font>
复制代码
二、SeleniumServer
在使用RemoteDriver时,必须在远程服务器启动一个SeleniumServer:
CODE:
<font size="4">java -jar selenium-server-standalone-2.20.0.jar -port 4446</font>
复制代码
三、How to setFirefox profile using RemoteWebDriver
CODE:
<font size="4">profile = new FirefoxProfile();
profile.setPreference("general.useragent.override",testData.getUserAgent());
capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("firefox_profile", profile);
driver = new RemoteWebDriver(new URL(“http://localhost:4446/wd/hub”),capabilities);
driverWait = new WebDriverWait(driver,TestConstant.WAIT_ELEMENT_TO_LOAD);
driver.get("http://www.google.com");</font>
复制代码
作者:
巴黎的灯光下
时间:
2017-7-14 15:13
向楼主致敬!
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2