是否有可能在运行时使用Appium从一个应用程序切换到另一个应用程序。
由于
答案 0 :(得分:11)
最后我找到了准确的答案,愿它对某些人有用
来源https://www.linkedin.com/grp/post/6669152-6027319885992841219?trk=groups-post-b-title
// App1 capabilities
String calculatorAppPackageName="com.android.calculator2";
String calculatorAppActivityName="com.android.calculator2.Calculator";
// App2 capabilities
String settingsAppPackageName="com.android.settings";
String settingsAppActivityName="com.android.settings.Settings";
@Before
public void setUp() throws MalformedURLException
{
DesiredCapabilities capabilities = DesiredCapabilities.android();
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "192.168.215.101:5555");
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, calculatorAppPackageName);
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, calculatorAppActivityName);
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testApp() throws InterruptedException, MalformedURLException
{
//Perform calculation in calculator
driver.findElement(By.name("4")).click();
driver.findElement(By.name("×")).click();
driver.findElement(By.name("3")).click();
driver.findElement(By.name("=")).click();
//launch settings App
driver.startActivity(settingsAppPackageName, settingsAppActivityName);
//Switch OFF WIFI
driver.findElement(By.id("com.android.settings:id/switchWidget")).click();
//Re launch calculator App
driver.startActivity(calculatorAppPackageName, calculatorAppActivityName);
//Validate results
String result = driver.findElement(By.className("android.widget.EditText")).getText();
System.out.println("Result : " + result);
Assert.assertEquals("Incorrect Result", "12", result);
}
答案 1 :(得分:4)
您可以通过使用新应用程序的属性重新实例化webdriver来更改应用程序。
driver = webdriver.Remote(appiumUrl,dcapabilityApp1)
[Your tests]
driver = webdriver.Remote(appiumUrl,dcapabilityApp2)
[New app tests]
只要您不关闭/断开仿真器/模拟器/设备,就会保留您的用户数据。
答案 2 :(得分:0)
driver.startActivity()方法可用于在应用之间切换。有关其工作原理的详细信息,请查看以下视频。
在YouTube上观看“Appium教程 - 在应用之间切换(联系人和短信)” https://youtu.be/sH1bHeDDj8U
答案 3 :(得分:0)
您可以使用:
(loop for var in list
when (cond1 var)
if (cond2 var)
collect var into list1
else
collect var into list2
finally (return (list list1 list2)))
使用相同的代码调用另一个应用程序。