selenium3.0 远程模式

时间:2023-03-09 03:37:34
selenium3.0  远程模式

准备工作:

1. 安装chrome浏览器

2. 下载selnium-server-standalone-3.0.1.jar

步骤:

1. java -jar selnium-server-standalone-3.0.1.jar  (默认ip:localhost、port:4444)

PS:作为单个server启动时,千万不要画蛇添足加个 -role hub/node

2.  测试脚本代码:

 public class NewTest {

     WebDriver driver;

     DesiredCapabilities desire;

     @Test
public void f() { driver.get("http://www.baidu.com");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } @BeforeMethod
public void beforeMethod() {
desire = DesiredCapabilities.chrome();
try {
driver = new RemoteWebDriver(new URL("http://10.1.7.104:4444/wd/hub"), desire);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.manage().window().maximize();
} @AfterMethod
public void afterMethod() {
driver.quit();
} }

注:以上代码所用到的IP为远程设备的IP。启用远程设备上的chrome浏览器,首先在远程设备上启动server(即:cmd--->java -jar selnium-server-standalone-3.0.1.jar),然后在本地执行测试脚本即可远程启动。