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(); // 設(shè)置需要驅(qū)動的瀏覽器,其他的瀏覽器都是以此類推 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); // 設(shè)置頁面加載超時的最大時長 } @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()); } } |