英文:
How to define platform-specific page elements for iOS and Android in a single place using QAF?
问题
我正在开发一个测试用例,需要在iOS和Android平台上使用QAF(Qmetry自动化框架)运行。我想采用页面对象的方法,在一个地方定义两个平台的元素,并在我的测试中重用它们。
在Appium中,我可以使用诸如@AndroidFindBy和@iOSXCUITFindBy之类的注解来实现这一点。以下是一个示例:
@HowToUseLocators(androidAutomation = LocatorGroupStrategy.ALL_POSSIBLE, iOSXCUITAutomation = LocatorGroupStrategy.ALL_POSSIBLE)
@AndroidFindBy(xpath = "//android.widget.TextView[@resource-id='merchant-name']")
@iOSXCUITFindBy(accessibility = "Home")
protected WebElement home;
这使我能够为Android和iOS指定不同的定位器,框架会根据平台自动选择适当的定位器。
然而,我在QAF中找不到类似的实现。在QAF中是否有实现相同结果的方法?我将非常感谢在QAF中如何解决这个问题的任何指导或建议。谢谢!
英文:
I'm developing a test case that needs to run on both iOS and Android platforms using QAF (Qmetry Automation Framework). I want to follow a Page Object approach where I can define elements for both platforms in a single place and reuse them in my tests.
In Appium, I can achieve this by using annotations like @AndroidFindBy and @iOSXCUITFindBy. Here's an example:
@HowToUseLocators(androidAutomation = LocatorGroupStrategy.ALL_POSSIBLE, iOSXCUITAutomation = LocatorGroupStrategy.ALL_POSSIBLE)
@AndroidFindBy(xpath = "//android.widget.TextView[@resource-id='merchant-name']")
@iOSXCUITFindBy(accessibility = "Home")
protected WebElement home;
This allows me to specify different locators for Android and iOS, and the framework automatically chooses the appropriate locator based on the platform.
However, I couldn't find a similar implementation in QAF. Is there a way to achieve the same result in QAF? I would greatly appreciate any guidance or suggestions on how to approach this in QAF. Thank you!
答案1
得分: 0
QAF 具有出色的跨平台测试自动化可重用性能力。
您应该利用 qaf 的 定位器存储库 功能,将定位器从代码中抽象出来。例如,如果使用页面类,而不是具有特定平台的类:
IosHomePage.java
@iOSXCUITFindBy(accessibility = "Home")
protected WebElement home;
AndroidHomePage.java
@AndroidFindBy(xpath = "//android.widget.TextView[@resource-id='merchant-name']")
protected WebElement home;
您可以使用单个类,并为每个平台(在本例中为 Android 和 iOS)创建单独的定位器存储库:
HomePage.java
@FindBy(locator = "home.ele.loc")
protected WebElement home;
您可以为每个平台创建定位器存储库,并在其中添加定位器:
resource
- appilcation.properties
- common
-
- android
- homescreen.properties
-
-
- ios
- homescreen.properties
-
-
在执行时,通过使用 env.resources
属性指定要使用的资源。例如,如果要运行 Android,可以使用以下方式:
env.resource=resource/common;resources/android
对于 iOS,可以使用以下方式:
env.resource=resource/common;resources/ios
另一种替代方法是特定于驱动程序的资源。在这种情况下,您的属性将如下所示:
env.resource=resource/common
android.resources=resources/android
ios.resources=resources/ios
参考链接:
还有来自 Perfecto 的有关定位器与能力的优质培训材料。
英文:
QAF has great capabilities of re-usability for cross platform test automation.
You should utilize locator repository feature of qaf to abstract locator out from the code. For example, if using page class,
instead of having platform specific class
IosHomePage.java
@iOSXCUITFindBy(accessibility = "Home")
protected WebElement home;
AndriodHomePage.java
@AndroidFindBy(xpath = "//android.widget.TextView[@resource-id='merchant-name']")
protected WebElement home;
you can have single class with separate locator repository for each platform (android and ios in this case)
HomePage.java
@FindBy(locator = "home.ele.loc")
protected WebElement home;
you can create locator repository for each platform and add locator in it
resource
- appilcation.properties
-common
-
- android
- homescreen.properties
-
-
-ios
- homescreen.properties
-
-
At the time of execution specify which resources you want to use by using env.resources
property. For example, if want to run for android
env.resource=resource/common;resources/android
for android
env.resource=resource/common;resources/ios
Another alternate is driver specific resources. In that case your properties will look like below
env.resource=resource/common
android.resources=resources/android
ios.resources=resources/ios
Refer:
There is also a good training material available from perfecto on Locator & Capabilities
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论