简体   繁体   English

在Appium iOS中使用Selenium Webdriver选择器

[英]Using Selenium Webdriver Selectors in Appium ios

A project I'm on is developing a web app at the same time as an ios app (for the same thing) and I'm hoping to be able to use existing Selenium tests, but we're having trouble with selectors. 我正在进行的一个项目正在与ios应用程序同时开发一个Web应用程序(出于同一目的),我希望能够使用现有的Selenium测试,但是选择器遇到了麻烦。 Is there a selector type or attribute name that can be used for both Selenium Webdriver and Appium ios, so that I can just set a variable to either browser or app and they run and work on both. 是否存在可用于Selenium Webdriver和Appium ios的选择器类型或属性名称,所以我可以将变量设置为浏览器或应用程序,并且它们可以在两者上运行并起作用。 Nobody on this project has used Appium before, so we are lacking a lot in knowledge. 该项目中没有人以前使用过Appium,因此我们缺乏很多知识。

I tried using IDs and found that ios doesn't work with them, changed to names and found that names have been removed from appium. 我尝试使用ID,发现ios无法使用它们,更改为名称,发现名称已从appium中删除。 If possible we'd prefer to use a selector that will be the same in the browser as it is in the app. 如果可能的话,我们希望使用一个选择器,该选择器在浏览器中与应用程序中的浏览器相同。

Thanks 谢谢

You can create one object repository file which contains the locators for both WebApp and iOS app. 您可以创建一个对象存储库文件,其中包含WebApp和iOS应用程序的定位器。 Then you have to follow the below process 然后,您必须按照以下过程

  1. Create WebDriver and AppiumDriver instances 创建WebDriverAppiumDriver实例
  2. Use the relevant drivers for locating the elements in WebApp as well as iOS app. 使用相关的驱动程序来查找WebApp和iOS应用程序中的元素。 We can use both the drivers within a test case. 我们可以在测试用例中同时使用两个驱动程序。

Please note that, the way WebDriver and AppiumDriver identifies the elements will be different. 请注意, WebDriverAppiumDriver标识元素的方式将有所不同。 For example, in WebDriver if an element is identified by using ID then similarly in AppiumDriver an element can be identified by using the findElementByAccessibilityId . 例如,在WebDriver如果通过使用ID标识元素,则类似地在AppiumDriver ,可以通过使用findElementByAccessibilityId标识元素。

Even though AppiumDriver uses the same logic which WebDriver uses, the method names will differ. 即使AppiumDriver使用与WebDriver相同的逻辑,方法名称也将有所不同。 Please find the link for all the methods used by AppiumDriver 请找到AppiumDriver使用的所有方法的链接

Hope this helps. 希望这可以帮助。

How about creating multiple object repositories and loading the relevant object repository based on the underlying platform? 如何创建多个对象存储库并基于基础平台加载相关的对象存储库?
1. So you need to store locators of both the platforms in separate repositories 1.因此,您需要将两个平台的定位器存储在单独的存储库中
2. Create a Interface / wrapper which would load relevant repository based on the platform on which tests are going to run. 2.创建一个接口/包装,它将基于要运行测试的平台加载相关的存储库。

Didn't quite get the question but for Appium You have separated annotations for bot iOS and Android platform similar as for web via: 尚未完全解决问题,但对于Appium,您已通过以下方式为bot iOS和Android平台(与网络类似)分隔了注释:

@FindBy(id="buttonOK")
private WebElement buttonPopUp;

Here is example for Android and iOS 这是Android和iOS的示例

@iOSFindBy(id = "lets_do_it")
@AndroidFindBy(id = "message_popup_dismiss_button")
@WithTimeout(unit = TimeUnit.SECONDS, time = 1)
private MobileElement buttonPopUp;

So in same pageObject you have covered both platforms. 因此,在同一个pageObject中,您已经涵盖了两个平台。

Mobile platform can work together, but recommendation is not to mix web and mobile, but mobile platforms can play together just fine, and is recommended so can share same code functionality. 移动平台可以协同工作,但建议不要将Web和移动平台混合使用,但是移动平台可以很好地协同工作,因此建议它们共享相同的代码功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM