一月蔷薇_456 发表于 2018-2-26 16:47:34

app应用appium框架简单自动化脚本

【备注:与公司有关的信息改用代替】
package connect..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 staticAndroidDriverdriver;
    @Test
    public void test() throws Exception {
         DesiredCapabilities capabilities = new DesiredCapabilities();
         //   File classpathRoot = new File(System.getProperty("user.dir"));
         //   File appDir = new File(classpathRoot, "apps/connet");
         //   File app = new File(appDir, "connect-_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..connect");
            capabilities.setCapability("appActivity", "com..activity.MainActivity_");
            driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
             driver.findElementById("com..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..connect:id/login_password_et").sendKeys("asdasdasd");
      driver.quit();

}
}

梦想家 发表于 2018-2-26 17:28:19

:handshake
页: [1]
查看完整版本: app应用appium框架简单自动化脚本