我想在我的“原始”应用A的测试会话中切换到不同的应用B.目的是将数据从应用B发送到应用A.
我已经尝试使用不同的功能重新启动我的驱动程序,并且我尝试在我的测试代码中使用两个不同的驱动程序。但这些都不起作用。
有没有人建议如何实现切换?我正在开发一台Mac btw。 提前谢谢!
答案 0 :(得分:0)
如果交换机在您的应用中实现并自动发生,那么您应该能够使用当前的应用定位器。
如果您需要单独打开应用,可以通过执行quit()
并在之后创建新来重新初始化驱动程序。
mobileDriver.quit()
mobileDriver = new IOSDriver(url, capabilities)
答案 1 :(得分:0)
如果您正在自动化Android测试,那么很容易。如果您是用户,只需自动执行步骤
adb shell input keyevent KEYCODE_HOME
或者您可以通过adb启动应用B,例如启动Chrome adb shell am start com.android.chrome
答案 2 :(得分:0)
参考此示例代码:
public class Switch_activity {
public static void main(String[] args) throws IOException, InterruptedException {
// TODO Auto-generated method stub
String Start_Server="D:\\Appium\\node.exe D:\\Appium\\node_modules\\appium\\bin\\appium.js";
Process process = Runtime.getRuntime().exec(Start_Server);
if(process!=null)
{
System.out.println("Appium Server is Started");
}
else
{
System.out.println("NOT able to Start the Server");
}
Thread.sleep(12000);
//Launch app
DesiredCapabilities capabilities= new DesiredCapabilities();
//device details
capabilities.setCapability("deviceName", "GT-I9300I");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4.4");
//app details
capabilities.setCapability("appPackage", "com.olacabs.customer");
capabilities.setCapability("appActivity", "com.olacabs.customer.ui.SplashActivity");
//appium server details
AndroidDriver driver= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Thread.sleep(8000);
driver.findElementById("android:id/button1").click();
//wait
WebDriverWait wait= new WebDriverWait(driver, 35);
WebElement until = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("com.olacabs.customer:id/button_ride_now")));
System.out.println(until.isDisplayed());
driver.findElementById("com.olacabs.customer:id/button_ride_now").click();
Thread.sleep(4000);
String text = driver.findElementById("com.olacabs.customer:id/button_ride_conform").getText();
System.out.println(text);
Thread.sleep(4000);
driver.sendKeyEvent(AndroidKeyCode.BACK);
//******************************************************
Thread.sleep(8000);
//Message app
Thread.sleep(8000);
//Try in this way
driver.startActivity("com.flipkart.android", "com.flipkart.android.activity.HomeFragmentHolderActivity");
WebDriverWait wait3= new WebDriverWait(driver, 35);
WebElement until3 = wait3.until(ExpectedConditions.presenceOfElementLocated(By.id("com.flipkart.android:id/search_widget_textbox")));
System.out.println(until3.isDisplayed());
driver.findElementById("com.flipkart.android:id/search_widget_textbox").click();
Thread.sleep(4000);
if(process!=null)
{
Thread.sleep(4000);
process.destroy();
System.out.println("Appium Server is Stopped");
}
}
}