package org.coderinfo.demo; import java.net.URL; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.AssertJUnit; /** * @author CoderInfo * @E-mail coderinfo@163.com * */ public class RemoteWebDriverDemo { private static final String URL = "http://www.baidu.com"; private static WebDriver driver; @Before public void setUp() throws Exception { DesiredCapabilities dc = DesiredCapabilities.chrome(); // 设置需要驱动的浏览器,其他的浏览器都是以此类推 driver = new RemoteWebDriver(new URL( "http://10.127.206.130:4444/wd/hub"), dc); // 这个URL // 10.127.206.130 // 是要remote PC 的IP // Address,需要改为你自己的 driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); // 设置页面加载超时的最大时长 } @After public void tearDown() throws Exception { driver.quit(); } @Test public void test() throws InterruptedException { driver.get(URL); // 访问度娘首页 driver.findElement(By.id("kw")).sendKeys("CoderInfo"); driver.findElement(By.id("su")).click(); Thread.sleep(10000); AssertJUnit.assertEquals("CoderInfo_百度搜索", driver.getTitle()); } } |