赞
踩
用driver.activityApp("appname")
公司尤为app,启动的activityty是.icon.ActivityDefault,启动完成后变为.view.main.MainActivity
代码
- package wconcept;
-
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.sql.Driver;
- import java.util.concurrent.TimeUnit;
-
- import org.openqa.selenium.By;
-
- import org.openqa.selenium.remote.DesiredCapabilities;
- import org.testng.Assert;
- import org.testng.annotations.*;
- import io.appium.java_client.android.Activity;
- import io.appium.java_client.android.AndroidDriver;
- import io.appium.java_client.remote.MobileCapabilityType;
- public class login {
- public static AndroidDriver driver;
- @BeforeTest()
- public void open() throws MalformedURLException {
- DesiredCapabilities capabilities = new DesiredCapabilities();
- capabilities.setCapability("deviceName","1223");
- capabilities.setCapability("automationName","Appium");
- capabilities.setCapability("platformName","Android");
- capabilities.setCapability("platformVersion","7.0");
-
- //配置测试apk
- capabilities.setCapability("appPackage", "com.sh.wcc");
- capabilities.setCapability("appActivity", ".icon.ActivityDefault ");
- //capabilities.setCapability("waitActivity", ".icon.ActivityDefault ");
- // capabilities.setCapability("sessionOverride", true); //每次启动时覆盖session,否则第二次后运行会报错不能新建session
- // capabilities.setCapability("unicodeKeyboard", true); //设置键盘
- // capabilities.setCapability("resetKeyboard", false); //设置默认键盘为appium的键盘
- // URL url = new URL("http://127.0.0.1:4723/wd/hub");
- //
- // driver = new AppiumDriver(url, capabilities);
- // String sessionId = driver.getSessionId().toString();
- driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
- driver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS);
-
- }
- @Test
- public void login() throws MalformedURLException, InterruptedException {
- //"com.sh.wcc", ".view.main.MainActivity"
- //driver.getCommandExecutor()
- //driver.startActivity(new Activity("com.sh.wcc", ".view.main.MainActivity"));
- System.out.println(driver.currentActivity());
-
- driver.findElement(By.xpath("//*[@text='确定']")).click();
- driver.findElement(By.xpath("//*[@text='允许']")).click();
- driver.findElement(By.xpath("//*[@text='允许']")).click();
- Thread.sleep(10000);
- driver.findElement(By.id("com.sh.wcc:id/iv_right_close")).click();
-
- driver.activateApp("com.sh.wcc");
-
-
- driver.findElement(By.xpath("//*[@text='我']")).click();
-
- //点击登录
- driver.findElement(By.id("com.sh.wcc:id/avatar")).click();
- //点击密码登录
- driver.findElement(By.xpath("//*[@text='密码']")).click();
- //输入账号密码
- driver.findElement(By.xpath("//*[@text='请填写手机号码']")).sendKeys("user");
- driver.findElement(By.xpath("//*[@text='请填写密码']")).sendKeys("pwd");
- //登录
- driver.findElement(By.id("com.sh.wcc:id/sign_in_btn")).click();
-
- String name=driver.findElement(By.id("com.sh.wcc:id/nickName")).getText();
- System.out.println(name);
- Assert.assertEquals("一二", name);
- }
-
-
-
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。