JavaAppium4.0[andriod_webapp]

Java結合TestNG單元測試框架,實現移動端andriod_webapp測試【源碼】

/*
 * @FileName Test_Android_WebApp:
 * @author davieyang
 * @create 2018-11-22 14:17
 */
package testscript;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class Test_Android_WebApp {
    AndroidDriver driver;
    @BeforeClass
    public void setUp() throws MalformedURLException{
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
        caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4");
        caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        caps.setCapability(MobileCapabilityType.DEVICE_NAME,"Moto X");
        driver = new AndroidDriver (new URL("http://127.0.0.1:4723/wd/hub"), caps);
        driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
    }
    @Test
    public void testExample(){
        driver.get("https://www.gmail.com");
        WebElement username=driver.findElement(By.name("Email"));
        username.sendKeys("test");
        WebElement password=driver.findElement(By.name("Passwd"));
        password.sendKeys("test");
        WebElement signIn=driver.findElement(By.name("signIn"));
        signIn.click(); }
    @AfterClass
    public void tearDown(){
        driver.quit();
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章