selenium+java項目實戰---百度輸入框


最近對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("斷言失敗");
        }
        
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM