For example, `config.browser_name` is deprecated in favor of `config.driver_name`. Main reason – «browser» term is not relevant to mobile testing, where in a lot of cases we test user actions in app, not browser.
New
`from selene import browser`
– to be used instead of `from selene.support.shared import browser`.
No difference between Config and SharedConfig anymore. The new, completely refactored, Config is now used everywhere and allows to customize browser instance in a more convenient way.
Adds ability to use `browser.with_(**config_options_to_override)` to create new browser instance, for example:
python
from selene import browser
chrome = browser
firefox = browser.with_(driver_name='firefox')
edge = browser.with_(driver_name='edge')
...
customizing all browsers at once:
browser.config.timeout = 10
as alternative to:
python
from selene import Browser, Config
chrome = Browser(Config())
firefox = Browser(Config(driver_name='firefox'))
edge = Browser(Config(driver_name='edge'))
...
customizing all browsers:
chrome.config.timeout = 10
firefox.config.timeout = 10
edge.config.timeout = 10
`browser.config.driver_options` + `browser.config.driver_remote_url`
Finally, you can delegate building driver to config manager by passing `driver_options` and `driver_remote_url` to it:
python
import dotenv
from selenium import webdriver
from selene import browser, have
def test_complete_task():
options = webdriver.ChromeOptions()
options.browser_version = '100.0'
options.set_capability(
'selenoid:options',
{
'screenResolution': '1920x1080x24',
'enableVNC': True,
'enableVideo': True,
'enableLog': True,
},
)
browser.config.driver_options = options <- 🥳
project_config = dotenv.dotenv_values()
browser.config.driver_remote_url = ( <- 🎉🎉🎉
f'https://{project_config["LOGIN"]}:{project_config["PASSWORD"]}'
f'selenoid.autotests.cloud/wd/hub'
)
browser.open('http://todomvc.com/examples/emberjs/')
browser.should(have.title_containing('TodoMVC'))
browser.element('new-todo').type('a').press_enter()
browser.element('new-todo').type('b').press_enter()
browser.element('new-todo').type('c').press_enter()
browser.all('todo-list>li').should(have.exact_texts('a', 'b', 'c'))
`browser.open()` without args
Will just open driver or do nothing if driver is already opened.
Can also load page from `browser.config.base_url` if it is set and additional experimental `browser.config._get_base_url_on_open_with_no_args = True` option is set (that is `False` by default).
Automatic driver rebuilding still happens on `browser.open`, but...
but can be configured as follows:
- can be disabled by setting `browser.config.__reset_not_alive_driver_on_get_url = False`,
that is `True` by default
- can be enabled on any explicit or implicit call to `browser.config.driver`,
if set `browser.config.rebuild_not_alive_driver = True` (that is `False` by default)
Appium support out of the box:)
Yet you have to install it manually. But given installed via `pip install Appium-Python-Client` or something like `poetry add Appium-Python-Client`, running tests on mobile devices is as easy as...
Running locally against Appium server:
python
from appium.options.android import UiAutomator2Options
from appium.webdriver.common.appiumby import AppiumBy
from selene import browser, have
android_options = UiAutomator2Options()
android_options.new_command_timeout = 60
android_options.app = 'wikipedia-alpha-universal-release.apk'
android_options.app_wait_activity = 'org.wikipedia.*'
browser.config.driver_options = android_options
Possible, but not needed, because will be used by default:
browser.config.driver_remote_url = 'http://127.0.0.1:4723/wd/hub'
by_id = lambda id: (AppiumBy.ID, f'org.wikipedia.alpha:id/{id}')
GIVEN
browser.open()
browser.element(by_id('fragment_onboarding_skip_button')).click()
WHEN
browser.element((AppiumBy.ACCESSIBILITY_ID, 'Search Wikipedia')).click()
browser.element(by_id('search_src_text')).type('Appium')
THEN
browser.all(by_id('page_list_item_title')).should(
have.size_greater_than(0)
)
Running remotely against Browserstack server:
python
from appium.options.android import UiAutomator2Options
from appium.webdriver.common.appiumby import AppiumBy
from selene import browser, have
options = UiAutomator2Options()
options.app = 'bs://c700ce60cf13ae8ed97705a55b8e022f13c5827c'
options.set_capability(
'bstack:options',
{
'deviceName': 'Google Pixel 7',
'userName': 'adminadminovych_qzqzqz',
'accessKey': 'qzqzqzqzqzqzqzqzqzqz',
},
)
browser.config.driver_options = options
browser.config.driver_remote_url = 'http://hub.browserstack.com/wd/hub'
by_id = lambda id: (AppiumBy.ID, f'org.wikipedia.alpha:id/{id}')
GIVEN
browser.open() not needed, but to explicitly force appium to open app
WHEN
browser.element((AppiumBy.ACCESSIBILITY_ID, 'Search Wikipedia')).click()
browser.element(by_id('search_src_text')).type('Appium')
THEN
browser.all(by_id('page_list_item_title')).should(
have.size_greater_than(0)
)
A lot of other local, remote and mobile test examples at...
https://github.com/yashaka/selene/tree/master/examples
autocomplete for entity.with_(HERE)
Other
Deprecated
- `browser.save_screenshot` in favor of `browser.get(query.screenshot_saved())`
- `browser.save_page_source` in favor of `browser.get(query.page_source_saved())`
- `browser.last_screenshot` in favor of `browser.config.last_screenshot`
- `browser.last_page_source` in favor of `browser.config.last_page_source`
- `match.browser_has_js_returned` in favor of `match.browser_has_script_returned`
- `have.js_returned` in favor of `have.script_returned`
- `have.js_returned_true(...)` in favor of `have.script_returned(True, ...)`
- `browser.config.get_or_create_driver`
- `browser.config.reset_driver`
- use `selene.browser.config.driver = ...`
- `browser.config.browser_name` in favor of `browser.config.driver_name`
Removed
- from selene.support.shared import SharedConfig, SharedBrowser
- from selene.core.entity import BrowserCondition, ElementCondition, CollectionCondition
Removed deprecated
- shared.browser.config.desired_capabilities
- shared.browser.config.start_maximized
- shared.browser.config.start_maximized
- shared.browser.config.cash_elements
- shared.browser.config.quit_driver
- shared.browser.latest_page_source
- shared.browser.quit_driver
- shared.browser.set_driver
- shared.browser.open_url
- shared.browser.elements
- shared.browser.wait_to
- shared.browser.title
- shared.browser.take_screenshot
- jquery_style_selectors
Removed not deprecated
- shared.browser.config.Source
- renamed to shared.browser.config._Source.
Currently, is used nowhere in Selene
- shared.browser.config.set_driver (getter and setter)
- shared.browser.config.counter
- use shared.browser.config._counter instead, and better – not use it;)
- shared.browser.config.generate_filename
- use shared.browser.config._generate_filename instead, and better – not use it;)
2.0.0b15-b17
Dependencies
- update selenium (with weakened dependency to >=4.4.3)
- update webdriver_manager (with weakened dependency to >=3.8.5)