1.查看網頁的cookie信息html
1 //查看cookie 登陸後的cookie 2 Set<Cookie> setcoke= driver.manage().getCookies(); 3 for(Cookie str: setcoke){ 4 System.out.println("cookie="+str); 5 }
for(Iterator<Cookie> iterator = setcoke.iterator();iterator.hasNext();){ System.out.print(iterator.next()+" ******"); }
2.測試數據參數化,數據庫,批量化,同時set集合的讀取和使用java
//測試數據參數化測試 @Test(enabled=true,dataProvider="datas",timeOut=120000,dataProviderClass=dlTest.class) public void dlTest_6(String users,String pass) throws InterruptedException{ driver=bmm.Login(users, pass, 0); System.out.println("users="+users); //查看cookie 登陸後的cookie Set<Cookie> setcoke= driver.manage().getCookies(); for(Cookie str: setcoke){ System.out.println("cookie="+str); } /* //查看cookie for(Iterator<Cookie> iterator = setcoke.iterator();iterator.hasNext();){ System.out.print(iterator.next()+" ******"); } */ String str_dlemail1=driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div")).getText(); System.out.println("dlTest_6實際結果:"+str_dlemail1); Assert.assertEquals("登陸成功", str_dlemail1); } //登陸數據等同記事本 @DataProvider public static Object[][] datas(){ return new Object[][]{ new Object[]{"test@qq.com","123456"}, new Object[]{"test1@qq.com","123456"}, }; }
3.invocationCount表明執行次數,timeOut超時時間設置數據庫
@Test(enabled = false,invocationCount=1)cookie
4.等待元素加載完成後,在繼續執行。app
WebDriverWait wait = new WebDriverWait(driver,100); wait.until(new ExpectedCondition<WebElement>(){ @Override public WebElement apply(WebDriver d) { return d.findElement(By.xpath("html/body/div[1]/div/div/div/form/table/tbody/tr[12]/td[2]/div/div/img")); }});
封裝成函數後爲:ide
/** * 等待元素出現後再執行 * 也就是等待元素對象加載完成 * driver驅動,By對象 * return 元素對象 * */ public WebElement ElementFinish(WebDriver driver,By by ){ WebDriverWait wait = new WebDriverWait(driver,100); return wait.until(new ExpectedCondition<WebElement>(){ @Override public WebElement apply(WebDriver d) { return d.findElement(by); }}); }
5.操做js代碼函數
//控制滾動條 下拉到最後 把滾動條下拉到最後,測試
String high="scroll(0,10000);"; ((JavascriptExecutor)driver).executeScript(high);
6.判斷元素是否存在spa
WebElement linkUsername = driver.findElement(By.xpath("//a[contains(text(),"+username+")]"));code