【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(); } }
不积跬步,无以致千里;不集小流,无以成江海。
如转载本文,请还多关注一下我的博客:https://www.cnblogs.com/Owen-ET/;
我的Github地址:https://github.com/Owen-ET————————————
无善无恶心之体, 有善有恶意之动, 知善知恶是良知, 为善去恶是格物。