使用serenity BDD的java Appium Android switch应用程序(本机和chrome)
我将serenity与appium(v2.3.12)结合使用
我的场景需要将应用程序从本机切换到open chrome,并验证表单以创建新帐户,然后返回本机并尝试登录
我用的是宁静的经典方式。属性来实例化appiumDriver并使用UIAutomator2自动化应用程序。 当我需要切换到chrome时,我会使用一个新的AppiumDriver,它具有相同的url和如下新功能:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("automationName", "UIAutomator2");
capabilities.setCapability("browserName", "Chrome");
capabilities.setCapability("UDID", udid);
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "emulator-5554");
capabilities.setCapability("platformVersion", "11.0");
AppiumDriver newDriver = new AndroidDriver(new URL(url), capabilities);
Chrome启动良好,我可以执行我的操作
但问题就在这里:当我不想切换回时
我尝试了很多方法,但到目前为止都没有成功:
第一次尝试是通过以下方式回拨我的应用程序:
((AndroidDriver)((WebDriverFacade) getDriver()).getProxiedDriver()).launchApp();
或者
((AndroidDriver)((WebDriverFacade) getDriver()).getProxiedDriver()).resetApp();
本机应用程序启动,但驱动程序无法找到任何元素,当我尝试获取PageSource时:
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not proxy. Proxy error: 'GET /wd/hub/session/f2dd1d65-351f-4845-b321-298e41b7df4d/source' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details
第二次尝试: 做一个测试。在使用第二个appiumDriver之前退出第一个appiumDriver。在chrome操作后启动app(),我得到以下信息:
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
我还尝试为每个appiumDriver使用两个不同的appium服务器
也许解决方案是在退出并在chrome中执行操作后重新启动serenity appiumDriver,因为我尝试启动第三个appiumDriver,它运行良好,并在本机应用程序中找到元素,但它与serenity的PageObject不起作用,我不知道如何在测试中退出并从serenity重新启动appiumDriver
同样的过程在iOS上也可以正常工作,当我重新打开应用程序元素时,它们会被正确找到。也许问题在于serenity处理UIAutomator2的方式
# 1 楼答案
我建议一种解决方法。尽量不要创建Chrome驱动程序。当你想离开应用(主应用)打开Chrome时,只需点击Android Home(或Back)按钮返回主屏幕。然后点击Chrome图标,检查是否可以继续与之交互。如果是,那就继续使用Chrome,直到你想回到应用程序。使用:
或者
对于您遇到的例外情况,我认为这来自您管理多个驱动程序的方式。当你切换到Chrome驱动程序时,你的主应用程序驱动程序会话似乎意外地调用了quit()。我不确定你的代码结构如何。但如果你不想通过上述解决方法来解决这个问题,那么仔细管理你的驱动程序可能是一个不错的方法
有关SessionNotFoundExceptionhere的详细信息