gpt4 book ai didi

appium - 如何在运行时从一个应用程序切换到另一个应用程序

转载 作者:行者123 更新时间:2023-12-04 01:54:18 26 4
gpt4 key购买 nike

是否有可能在运行时使用 Appium 从一个应用程序切换到另一个应用程序。

谢谢

最佳答案

最后我找到了准确的答案,可能对某些人有用

来源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);
}

关于appium - 如何在运行时从一个应用程序切换到另一个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22710538/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com