WebDriver之 RemoteWebDriver

当本机上没有浏览器,需要远程调用浏览器进行自动化测试时,需要用到RemoteWebDirver.

一、使用RemoteWebDriver

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);

    }

}


二、SeleniumServer
在使用RemoteDriver时,必须在远程服务器启动一个SeleniumServer:
java -jar selenium-server-standalone-2.20.0.jar -port 4446

三、How to setFirefox profile using RemoteWebDriver
      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");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值