Mac + Appium + Java1.8学习之Android模拟器自动化测试脚本开发以及简易例子

高斋晓开卷,独共圣人语。这篇文章主要讲述Mac + Appium + Java1.8学习之Android模拟器自动化测试脚本开发以及简易例子相关的知识,希望能为你提供帮助。
直接上代码:

import io.appium.java_client.AppiumDriver; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.MalformedURLException; import java.net.URL; import static java.lang.Thread.sleep; public class TestXueqiuDemo { private AppiumDriver< WebElement> driver; @Before public void setUp() throws MalformedURLException { // set up appium DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("platformName", "android"); capabilities.setCapability("deviceName", "192.168.56.101:5555"); capabilities.setCapability("appPackage","com.xueqiu.android"); capabilities.setCapability("appActivity",".view.WelcomeActivityAlias"); driver = new AppiumDriver< WebElement> (new URL("http://127.0.0.1:4723/wd/hub"),capabilities); }@After public void tearDown() throws Exception{ //driver.quit(); System.out.println("测试结束!"); }@Test public void testDemo01() throws Exception { driver.findElementById("com.xueqiu.android:id/open").click(); int i = 0; for (i=0; i< 2; i++){ driver.findElementById("com.android.packageinstaller:id/permission_allow_button").click(); } //driver.findElementById("com.android.packageinstaller:id/permission_allow_button").click(); sleep(5000); //隐式等待 //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); System.out.println("暂停10s"); driver.findElementById("com.xueqiu.android:id/agree").click(); driver.findElementById("com.android.packageinstaller:id/permission_allow_button").click(); sleep(2000); driver.findElementByXPath("//*[@text=‘自选‘]").click(); }}

【Mac + Appium + Java1.8学习之Android模拟器自动化测试脚本开发以及简易例子】 

    推荐阅读