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.  测试脚本代码:

 1 public class NewTest {
 2     
 3     WebDriver driver;
 4     
 5     DesiredCapabilities desire;
 6 
 7     @Test
 8     public void f() {
 9 
10         driver.get("http://www.baidu.com");
11         try {
12             Thread.sleep(5000);
13         } catch (InterruptedException e) {
14             // TODO Auto-generated catch block
15             e.printStackTrace();
16         }
17 
18     }
19 
20     @BeforeMethod
21     public void beforeMethod() {
22         desire = DesiredCapabilities.chrome();
23         try {
24             driver = new RemoteWebDriver(new URL("http://10.1.7.104:4444/wd/hub"), desire);
25         } catch (MalformedURLException e) {
26             // TODO Auto-generated catch block
27             e.printStackTrace();
28         }
29         driver.manage().window().maximize();
30     }
31 
32     @AfterMethod
33     public void afterMethod() {
34         driver.quit();
35     }
36 
37 }
View Code

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

posted @ 2017-04-28 13:48  快乐生活740  阅读(306)  评论(0编辑  收藏  举报