简体   繁体   中英

How to only have one driver that can be used as Webdriver or Appiumdriver

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;

If the test runs on a device it uses appDriver and if it runs on the web it uses webDriver.

However this causes problems for shared methods such as driver.quit....I have to have more code to handle both types of driver...(eg if device test appDriver.quit, if web webDriver.quit).

Is there a way to just declare one driver (called driver) that can be cast to Appiumdriver or Webdriver as required by the test?

I could then use driver.quit and this would work regardless of whether the test is a device test or a web test?

Thanks for any help.

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{
}

The hierarchy of Appium is as follows. More details here

java.lang.Object
org.openqa.selenium.remote.RemoteWebDriver
io.appium.java_client.AppiumDriver<T>

So I suggest you can create instance of RemoteWebDriver class and then use it accordingly for web(selenium) and mobile(appium).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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