最近對java+selenium+testng+maven 做一個小項目的總結,並對工作中的框架在做一些小總結,大概目錄為:
1.項目實戰--百度登錄輸入框
2.項目的二次封裝
3.框架分層,及po模式
4.框架中的監聽及重跑
項目實戰:
百度輸入框,目錄格式:

package test.jun; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import junit.framework.Assert; public class login { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://www.baidu.com"); driver.findElement(By.linkText("登錄")).click(); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } driver.findElement(By.id("TANGRAM__PSP_10__footerULoginBtn")).click(); driver.findElement(By.id("TANGRAM__PSP_10__userName")).clear(); driver.findElement(By.id("TANGRAM__PSP_10__userName")).sendKeys("18582559217"); driver.findElement(By.id("TANGRAM__PSP_10__password")).clear(); driver.findElement(By.id("TANGRAM__PSP_10__password")).sendKeys("2222222222"); driver.findElement(By.id("TANGRAM__PSP_10__submit")).click(); //因為有驗證碼,我們以出現驗證碼為准,做為斷言 if(driver.findElement(By.id("TANGRAM__PSP_10__error")).isDisplayed()) { System.out.println("登錄成功"); }else { Assert.fail("斷言失敗"); } } }


