当前位置:   article > 正文

同一个app里面的activity不一样_androidstudio的mainactivity和别人的不一样

androidstudio的mainactivity和别人的不一样

用driver.activityApp("appname")

公司尤为app,启动的activityty是.icon.ActivityDefault,启动完成后变为.view.main.MainActivity

代码

  1. package wconcept;
  2. import java.net.MalformedURLException;
  3. import java.net.URL;
  4. import java.sql.Driver;
  5. import java.util.concurrent.TimeUnit;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.remote.DesiredCapabilities;
  8. import org.testng.Assert;
  9. import org.testng.annotations.*;
  10. import io.appium.java_client.android.Activity;
  11. import io.appium.java_client.android.AndroidDriver;
  12. import io.appium.java_client.remote.MobileCapabilityType;
  13. public class login {
  14. public static AndroidDriver driver;
  15. @BeforeTest()
  16. public void open() throws MalformedURLException {
  17. DesiredCapabilities capabilities = new DesiredCapabilities();
  18. capabilities.setCapability("deviceName","1223");
  19. capabilities.setCapability("automationName","Appium");
  20. capabilities.setCapability("platformName","Android");
  21. capabilities.setCapability("platformVersion","7.0");
  22. //配置测试apk
  23. capabilities.setCapability("appPackage", "com.sh.wcc");
  24. capabilities.setCapability("appActivity", ".icon.ActivityDefault ");
  25. //capabilities.setCapability("waitActivity", ".icon.ActivityDefault ");
  26. // capabilities.setCapability("sessionOverride", true); //每次启动时覆盖session,否则第二次后运行会报错不能新建session
  27. // capabilities.setCapability("unicodeKeyboard", true); //设置键盘
  28. // capabilities.setCapability("resetKeyboard", false); //设置默认键盘为appium的键盘
  29. // URL url = new URL("http://127.0.0.1:4723/wd/hub");
  30. //
  31. // driver = new AppiumDriver(url, capabilities);
  32. // String sessionId = driver.getSessionId().toString();
  33. driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
  34. driver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS);
  35. }
  36. @Test
  37. public void login() throws MalformedURLException, InterruptedException {
  38. //"com.sh.wcc", ".view.main.MainActivity"
  39. //driver.getCommandExecutor()
  40. //driver.startActivity(new Activity("com.sh.wcc", ".view.main.MainActivity"));
  41. System.out.println(driver.currentActivity());
  42. driver.findElement(By.xpath("//*[@text='确定']")).click();
  43. driver.findElement(By.xpath("//*[@text='允许']")).click();
  44. driver.findElement(By.xpath("//*[@text='允许']")).click();
  45. Thread.sleep(10000);
  46. driver.findElement(By.id("com.sh.wcc:id/iv_right_close")).click();
  47. driver.activateApp("com.sh.wcc");
  48. driver.findElement(By.xpath("//*[@text='我']")).click();
  49. //点击登录
  50. driver.findElement(By.id("com.sh.wcc:id/avatar")).click();
  51. //点击密码登录
  52. driver.findElement(By.xpath("//*[@text='密码']")).click();
  53. //输入账号密码
  54. driver.findElement(By.xpath("//*[@text='请填写手机号码']")).sendKeys("user");
  55. driver.findElement(By.xpath("//*[@text='请填写密码']")).sendKeys("pwd");
  56. //登录
  57. driver.findElement(By.id("com.sh.wcc:id/sign_in_btn")).click();
  58. String name=driver.findElement(By.id("com.sh.wcc:id/nickName")).getText();
  59. System.out.println(name);
  60. Assert.assertEquals("一二", name);
  61. }
  62. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/319807
推荐阅读
相关标签
  

闽ICP备14008679号