如何只拥有一个可以用作 Webdriver 或 Appiumdriver 的驱动程序 [英] How to only have one driver that can be used as Webdriver or Appiumdriver
问题描述
我正在编写一个测试自动化框架,该框架使用 AppiumDriver 在设备上运行一些测试,并使用 WebDriver 在网络上运行一些测试.
I am writing a test automation framework that runs some tests on devices using AppiumDriver and some on the web using WebDriver.
目前我声明了两个不同的驱动程序,如下所示:
Currently I am declaring two different drivers as shown below:
public static AppiumDriver appDriver = null;
public static RemoteWebDriver webDriver = null;
如果测试在设备上运行,则使用 appDriver,如果在网络上运行,则使用 webDriver.
If the test runs on a device it uses appDriver and if it runs on the web it uses webDriver.
然而,这会导致共享方法出现问题,例如 driver.quit....我必须有更多的代码来处理这两种类型的驱动程序...(例如,如果设备测试 appDriver.quit,如果 web 驱动程序.quit).
However this causes problems for shared methods such as driver.quit....I have to have more code to handle both types of driver...(e.g. if device test appDriver.quit, if web webDriver.quit).
有没有办法只声明一个驱动程序(称为驱动程序),可以根据测试的需要转换为 Appiumdriver 或 Webdriver?
Is there a way to just declare one driver (called driver) that can be cast to Appiumdriver or Webdriver as required by the test?
然后我可以使用 driver.quit,无论测试是设备测试还是网络测试,这都可以工作?
I could then use driver.quit and this would work regardless of whether the test is a device test or a web test?
感谢您的帮助.
推荐答案
Selenium 的层次结构如下.更多详情这里
The hierarchy of Selenium is as follows. More details here
interface Webdriver extends SearchContext{
}
class RemoteWebDriver implements Webdriver{
}
class ChromeWebDriver extends RemoteWebDriver{
}
class FirefoxWebDriver extends RemoteWebDriver{
}
Appium 的层次结构如下.更多详情这里
The hierarchy of Appium is as follows. More details here
java.lang.Object
org.openqa.selenium.remote.RemoteWebDriver
io.appium.java_client.AppiumDriver<T>
所以我建议你可以创建 RemoteWebDriver
类的实例,然后相应地将它用于 web(selenium) 和 mobile(appium).
So I suggest you can create instance of RemoteWebDriver
class and then use it accordingly for web(selenium) and mobile(appium).
这篇关于如何只拥有一个可以用作 Webdriver 或 Appiumdriver 的驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!