质量保证金 |将驱动程序从 Web 切换到 Mobile 或者 Vice verse 没有保持驱动程序实例并行

QAF | Switch driver from Web to Mobile or Vice verse is not holding the driver instance parallel

使用“switchDriver”在Web 和Mobile 之间切换。当我在 web 和 web 之间切换驱动程序时(例如:Chrome 到 Firefox 或 Vice Versa)驱动程序实例是并行的,但是当我在 Web 和移动设备之间切换驱动程序或反之亦然时,它并没有并行持有驱动程序实例。

注意:我使用的是两个不同的服务提供商。 Web (Browserstack) 和移动 (ExperiTest)。

@QAFTestStep(description = "I switch driver {drivername}") 
public static void iSwitchDriver(String drivername) {

if (drivername.equals("appiumDriver")) {
            getBundle().setProperty("remote.server","https://experitest/xxxx");
        } else { // chromeRemoteDriver/firefoxRemoteDriver/edgeRemoteDriver
            getBundle().setProperty("remote.server","https://browserstack/xxxx");
        }
        switchDriver(drivername); 
}

从 Web 切换到 Mobile 时的一些执行日志

11:53:23.937 [TestNG] INFO  c.q.q.a.step.TestStepListener - Invoking Teststep: And I take screenshot
11:53:23.938 [TestNG] INFO  c.q.q.a.ui.WebDriverCommandLogger - Executing screenshot parameters: {}
11:53:24.367 [TestNG] DEBUG c.q.qaf.automation.core.QAFTestBase - Capturing screen shotTest1_Test_EribankScenario_ntqee73ykjnh52.png
11:53:24.367 [TestNG] DEBUG c.q.qaf.automation.core.QAFTestBase - Info: 
11:53:24.367 [TestNG] INFO  c.q.q.a.step.TestStepListener - Completed Teststep: And I take screenshot
11:53:24.373 [TestNG] INFO  c.q.q.a.step.TestStepListener - Invoking Teststep: Given I switch driver "appiumDriver" with arguments: [appiumDriver]
11:53:24.374 [TestNG] INFO  c.q.q.a.ui.WebDriverCommandLogger - Executing quit parameters: {}
11:53:24.474 [TestNG] INFO  c.q.q.a.ui.WebDriverCommandLogger - command: quit[ param-1: {}] Result: null
11:53:24.474 [TestNG] INFO  c.q.q.automation.ui.UiDriverFactory - UI-driver tear down complete...
11:53:24.474 [TestNG] INFO  c.q.q.a.step.TestStepListener - Invoking Teststep: switch to {driverName} with arguments: [appiumDriver]
11:53:24.475 [TestNG] INFO  c.q.q.a.step.TestStepListener - Completed Teststep: switch to {driverName} with arguments: [appiumDriver]
11:53:24.475 [TestNG] INFO  c.q.q.a.step.TestStepListener - Completed Teststep: Given I switch driver "appiumDriver" with arguments: [appiumDriver]
11:53:24.489 [TestNG] INFO  c.q.q.a.step.TestStepListener - Invoking Teststep: Given I assert "Mobile.login.button" is present with arguments: [Mobile.login.button]
11:53:24.489 [TestNG] INFO  c.q.q.a.step.TestStepListener - Invoking Teststep: assert {loc} is present with arguments: [Mobile.login.button]
Driver not configured!... 
Using firefoxDriver as default value. Please configure driver to be used using 'driver.name' property
11:53:24.490 [TestNG] INFO  c.q.qaf.automation.core.QAFTestBase - Initializing Driver...browser_str:appiumDriver,base_url:http://www.google.com/,sel_server:https://experitest.com/wd/hub,port:4444
11:53:24.490 [TestNG] INFO  c.q.q.automation.ui.UiDriverFactory - Driver: appiumDriver
Oct 03, 2021 11:54:21 AM io.appium.java_client.remote.AppiumCommandExecutor lambda[=11=]
INFO: Detected dialect: OSS
11:54:21.718 [TestNG] INFO  c.q.qaf.automation.core.QAFTestBase - driver init done
11:54:21.719 [TestNG] INFO  c.q.q.a.ui.WebDriverCommandLogger - Executing findElements parameters: {"value":"//*[@id='loginButton']","using":"xpath"}

一些从移动端到网页端的执行日志:

1:54:31.317 [TestNG] INFO  c.q.q.a.step.TestStepListener - Completed Teststep: Given I assert "Mobile.login.button" is present with arguments: [Mobile.login.button]
11:54:31.323 [TestNG] INFO  c.q.q.a.step.TestStepListener - Invoking Teststep: Given I switch driver "firefoxRemoteDriver" with arguments: [firefoxRemoteDriver]
11:54:31.324 [TestNG] INFO  c.q.q.a.ui.WebDriverCommandLogger - Executing quit parameters: {}
11:54:38.295 [TestNG] INFO  c.q.q.a.ui.WebDriverCommandLogger - command: quit[ param-1: {}]
11:54:38.296 [TestNG] INFO  c.q.q.automation.ui.UiDriverFactory - UI-driver tear down complete...
11:54:38.296 [TestNG] INFO  c.q.q.a.step.TestStepListener - Invoking Teststep: switch to {driverName} with arguments: [firefoxRemoteDriver]
11:54:38.296 [TestNG] INFO  c.q.q.a.step.TestStepListener - Completed Teststep: switch to {driverName} with arguments: [firefoxRemoteDriver]
11:54:38.296 [TestNG] INFO  c.q.q.a.step.TestStepListener - Completed Teststep: Given I switch driver "firefoxRemoteDriver" with arguments: [firefoxRemoteDriver]
11:54:38.298 [TestNG] INFO  c.q.q.a.step.TestStepListener - Invoking Teststep: Given I open "https://demobank1.xxxxx.com/" with arguments: [https://demobank1.xxxxx.com/]
Driver not configured!... 
Using firefoxDriver as default value. Please configure driver to be used using 'driver.name' property
11:54:38.299 [TestNG] INFO  c.q.qaf.automation.core.QAFTestBase - Initializing Driver...browser_str:firefoxRemoteDriver,base_url:http://www.google.com/,sel_server:https://browserstack.com/grid1/wd/hub,port:4444
11:54:38.299 [TestNG] INFO  c.q.q.automation.ui.UiDriverFactory - Driver: firefoxRemoteDriver
Oct 03, 2021 11:54:42 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
11:54:42.900 [TestNG] INFO  c.q.qaf.automation.core.QAFTestBase - driver init done
11:54:42.900 [TestNG] INFO  c.q.q.a.ui.WebDriverCommandLogger - Executing maximizeCurrentWindow parameters: {}
11:54:43.222 [TestNG] INFO  c.q.q.a.ui.WebDriverCommandLogger - command: maximizeCurrentWindow[ param-1: {}] Result: {x=0, y=0, width=1920, height=1055}
11:54:43.222 [TestNG] INFO  c.q.q.a.step.TestStepListener - Invoking Teststep: get {url} with arguments: [https://demobank1.xxxxx.com/]

Appium 功能:

appium.capabilities.accessKey=asdljj.sdasdad.asdasdasd.asd
appium.capabilities.uuid=asdsd23424
appium.capabilities.platformName=android
appium.capabilities.app=cloud:com.xxxx.xxx/.LoginActivity
appium.capabilities.instrumentApp=true
appium.capabilities.appPackage=com.xxx.xxx
appium.capabilities.appActivity=com.xxx.xxx.LoginActivity
appium.capabilities.driverClass=io.appium.java_client.android.AndroidDriver

浏览器功能:

chrome.additional.capabilities={'name': 'Chrome - Test Run','browserName': 'chrome', 'browserVersion': '89.0' }

我已经尝试参考以下链接寻求解决方案: Switch back and forth between drivers in qmetry ,

通过设计,当观察到任何特定于驱动程序的 属性 更改时,qaf 会拆除驱动程序实例。您可以尝试删除配置侦听器。

    ConfigurationManager.getBundle().clearConfigurationListeners();

它可能会影响资源加载行为。

为了克服这个问题,您可以使用 driver specific resources feature,它允许您创建单独的属性 file/folder 并设置为驱动程序资源。这样,在更改驱动程序时,您无需为加载资源编写代码。例如:

env.name=qa
env.resources=resources/common;resources/${env.name}
driver.name=androidRemoteDriver

android.resources=resources/android;resources/mobilecloude.properties
ios.resources=resources/ios;resources/mobilecloude.properties
chrome.resources=resources/web;resources/browsercloude.properties
firefox.resources=resources/web;resources/browsercloude.properties
edge.resources=resources/web;resources/browsercloude.properties

在上面的例子中,

    如果 android/ios/desktop-web. 的定位器不同,
  • resources/webresources/androidresources/ios 可能包含定位器存储库
  • resources/${env.name} 可能包含特定于环境的资源。例如特定于环境的测试数据。