app應用appium框架簡單自動化指令碼
阿新 • • 發佈:2019-02-18
【備註:與公司有關的資訊改用[xxx]代替】
package connect.[xxx].com;
import java.net.URL;
import java.util.concurrent.TimeUnit; import junit.framework.Assert; import io.appium.java_client.android.AndroidDriver; import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Demo1 { public static AndroidDriver driver; @Test
public void test() throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities();
// File classpathRoot = new File(System.getProperty("user.dir"));
// File appDir = new File(classpathRoot, "apps/[xxx] connet");
// File app = new File(appDir, "connect-[xxx]_connect.apk");
capabilities.setCapability("device","Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "H60_L21");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4");
// capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("unicodeKeyboard" ,"True");
capabilities.setCapability("resetKeyboard", "True");
capabilities.setCapability("appPackage", "com.[xxx].connect");
capabilities.setCapability("appActivity", "com.[xxx].activity.MainActivity_");
driver = new AndroidDriver(new URL(" http://127.0.0.1:4723/wd/hub"), capabilities);
driver.findElementById("com.[xxx].connect:id/me_rbtn").click();
Thread.sleep(1000);
driver.scrollTo("設定");
driver.findElementByName("設定").click();
Thread.sleep(2000); driver.findElementByName("退出登入").click(); Assert.assertTrue("介面找不到:" + "登陸", driver.getPageSource().contains("登陸")); driver.findElementById("com.[xxx] .connect:id/login_password_et").sendKeys("asdasdasd");
driver.quit();
}
}
import java.util.concurrent.TimeUnit; import junit.framework.Assert; import io.appium.java_client.android.AndroidDriver; import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Demo1 { public static AndroidDriver driver; @Test
public void test() throws Exception { DesiredCapabilities capabilities = new DesiredCapabilities();
// File classpathRoot = new File(System.getProperty("user.dir"));
// File appDir = new File(classpathRoot, "apps/[xxx]
// File app = new File(appDir, "connect-[xxx]_connect.apk");
capabilities.setCapability("device","Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "H60_L21");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4");
// capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("unicodeKeyboard" ,"True");
capabilities.setCapability("resetKeyboard", "True");
capabilities.setCapability("appPackage", "com.[xxx].connect");
capabilities.setCapability("appActivity", "com.[xxx].activity.MainActivity_");
driver = new AndroidDriver(new URL("
driver.findElementByName("設定").click();
Thread.sleep(2000); driver.findElementByName("退出登入").click(); Assert.assertTrue("介面找不到:" + "登陸", driver.getPageSource().contains("登陸")); driver.findElementById("com.[xxx]
driver.quit();
}
}