yashaka / selene

User-oriented Web UI browser tests in Python
https://yashaka.github.io/selene/
MIT License
695 stars 151 forks source link

Selene and Appium – how to make them work? #213

Open yashaka opened 4 years ago

yashaka commented 4 years ago

Currently if you use

from selene.support.shared import browser

browser.config.driver = yourAppiumDriver
...

it will fail with something like:

    self.browser_name = value and value.name  # overwrites default browser_name
  File "C:\Users\...\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 215, in name
    raise KeyError('browserName not specified in session capabilities')
KeyError: 'browserName not specified in session capabilities'

For now it's unclear should we fix the "shared browser" in Selene or not... Maybe it's good to keep it as it is, i.e. web-ui oriented, not web+mobile oriented... We'll see...

But now, the core API of selene should work:

from selene import Browser, Config

mobile = Browser(Config(
    driver=yourAppiumDriver,
    timeout=10, 
    ...))

# ...
aleksandr-kotlyar commented 4 years ago

But now, the core API of selene should work:

from selene import Browser, Config

mobile = Browser(Config(
   driver=yourAppiumDriver,
   timeout=10, 
   ...))

So then u should throw mobile to each test as a fixture, and call mobile.element(..)?

yashaka commented 4 years ago

you can manage your mobile instance in a whatever way you like. Just keep it as a global variable and import where do you need it

# tests/conftest.py

from selene import Browser, Config

mobile = Browser(Config(
   driver=yourAppiumDriver,
   timeout=10, 
   ...))
# tests/test_app.py

from tests.conftest import mobile

def test_something():
      mobile. ...

or use it as an explicit fixture:

# tests/conftest.py

from selene import Browser, Config
import pytest

# here it is implemented yet as a global variable, but you can change implementation to create it in the fixture below each time...
mobile_browser = Browser(Config(
     driver=yourAppiumDriver,
     timeout=10, 
     ...))

@pytest.fixture
def mobile()
    return mobile_browser
# tests/test_app.py

def test_something(mobile):
      mobile. ...
aleksandr-kotlyar commented 4 years ago

@yashaka understood. Thank you!

yashaka commented 1 year ago

Example of project with configured Appium + Selene - https://github.com/qa-guru/mobile-tests-13-py