Is it possible to use Selenium WebDriver and Appium WebDriver in the same code?

Hi everybody,

I try to start my application on my Android phone (with appium), and, in the same time, a chrome browser on my local computer (with selenium). My goal is to test communication between the chrome browser(on my computer) and my android application. Problem : when I try to switch context for appium webdriver, that’s doesn’t work : no context exists !

Can someone can helping me ?

Thx

Max

2 Likes

yes you can, no need to switch the context, use the web/mobile driver as your test case flow goes.

you share the error and test code.
I have used it with iOSdriver and Safari web driver, works fine.

Hi Venkatesh,

Could you give us some sample codes of your approach switching between appium and web driver?

Cheers!
Moss

Webdriver driver;

Some test code as webdriver…

Now we need e.g. iOSDriver do cast
(iOSDriver) driver.findElementBy…

Or as Appium driver cast
(AppiumDriver) driver.some_command…

Hi @max,
You should create two drivers (an Appium driver and a Selenium driver) and then you could interact with them simultaneously. For example, to work with a local Appium server and a local Chrome, in python:

from appium.webdriver.webdriver import WebDriver as AppiumDriver
from selenium.webdriver.chrome.webdriver import WebDriver as ChromeDriver

appium_capabilities = {   
    'automationName': 'Appium',
    'platformName': 'Android',
    'deviceName': 'Android',
    'app': 'APK_PATH'
}
appium_driver = AppiumDriver(command_executor='http://127.0.0.1:4723/wd/hub',
                             desired_capabilities=appium_capabilities)

chrome_driver = ChromeDriver(executable_path='CHROMEDRIVER_PATH')
chrome_driver.get('http://www.google.com')

appium_driver.find_element(...)
chrome_driver.find_element(...)

appium_driver.quit()
chrome_driver.quit()
1 Like

@max
the code @rgonalo provided is same what i would have suggested, try using that.

Follow this link if app is not showing NATIVE/WEBVIEW context(s)

https://toolsqa.com/mobile-automation/appium/how-to-inspect-and-automate-webview-in-hybrid-app/

Hi,

Thank you to all.
I’m able now to do what I want.
A special thank to @rgonalo !

Thx guys :wink:

@max
Dear I just wants to say the description of your question does not match with your question subject

Regards
Amit Jain

w.r.t to the same context, I have few questions.
My scenarios is that I need the Appium Android driver and Selenium Web driver to be interacted for data comparision purposes.
When the data is submitted from Mobile app (Android driver), the same data goes and sit in the Desktop Web browser application (Selenium Web driver).
I now want to compare these two data while opening the browser outside of the mobile as a standalone browser and ensure that the match is happening.

can someone please throw the inputs regarding this?

In above example, Chrome is opened as a standalone browser, not inside the mobile. You can use the same approach: open both drivers, submit data from Appium driver, get data from chrome_driver and check that they are equals.

How would you make sure both drivers(selenium webdriver and appiumdriver) are initiated on the same node if I were executing tests on grid? In my case I want to need to interact with selenium webdriver and then with Appium WinAppDriver in the same test. So I can perform file upload.

Can you share Java Code Snippet for having chromedriver been launched within app.
Currently trying to do a context switch after launching sdk to web view. Here to execute script, it is asking for chromedriver to be installed.

Not able to send chromedriver in desired capabilities stating both AppName and ChromeDriver is not allowed. Can some one help here. Few articles are there to set chromedriver at run time, but not sure how to set them at runtime. I am executing scripts via TestNG

I tried the same approach, i.e. AppiumDriver for mobile app in the Android device and Selenium Webdriver for website on desktop

but my mobile app( appium driver) quits as soon as webdriver is instantiated.

I’m trying to do similar thing but with appium 2.0(server) and webdriverio(client) and selenium for chrome browser. I getting an error ‘TypeError: $ is not a function’
can someone please help ?

I’m interested in knowing if I can use same webdriver.io code for testing desktop web and hybrid mobile, what happened with you?