Selenium for Python
Project description
Selenium for Python
Introduction
This package is a library designed to simplify your work with Selenium WebDriver and based on py-selenium-auto-core solution.
Supported browsers
- Chrome
Note: Support for popular browsers will be expanded in the future
Supported Python Versions
- Python 3.7-3.12
Installation
If you have pip on your system, you can simply install or upgrade the Python bindings:
pip install -U py-selenium-auto
Alternately, you can download the source distribution from PyPI, unarchive it, and run:
python setup.py install
Template
To start the project using this solution, you can look into py-selenium-auto-template .
Quick start
- Add the dependency in your project
- Create conftest.py file and add the following code:
@pytest.fixture(scope="session", autouse=True)
def setup_session(request):
# TODO: workaround to set calling root path, because pytest runs from the root dir
work_dir = RootPathHelper.current_root_path(__file__)
os.chdir(work_dir)
It's necessary to set root dir for your test directory. It is assumed that your project structure will look like this:
src/
__init__.py
some_code/
tests/ # Any name
__init__.py
resources/
some_code/
- Create instance of Browser in your test:
browser = BrowserServices.Instance.browser
- Use Browser's methods directly for general actions, such as navigation, window resize, scrolling and alerts handling:
browser.maximize()
browser.go_to("https://google.com")
browser.wait_for_page_to_load()
- Use ElementFactory class's methods to get an instance of each element:
my_text_box = BrowserServices.Instance.service_provider.element_factory().get_text_box(Locator.by_xpath("XPATH"), "Name")
Or you can inherit a class from Form class and use existing ElementFactory:
self.my_text_box = self._element_factory.get_text_box(Locator.by_xpath("XPATH"), "Name")
- Call element's methods to perform action with element:
my_text_box.type("example@email.com")
- Quit browser at the end:
browser.quit()
Configuration
This file is used to configure your browser settings, as well as other settings.By default, your solution will use the file from this project.
Copy the following file to your solution in tests/resources
to configure it yourself
License
Library's source code is made available under the Apache 2.0 license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for py_selenium_auto-0.4.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e31ea6a2774f3ee1bb582510c6081d74af06af56ca552899b8900d30fcc9a671 |
|
MD5 | 8aefb9710e66951cf78d984d7fd75e82 |
|
BLAKE2b-256 | 7ba2e13b329aa7cfd111b4157da979e52bace2015718f3e94c13dc87a0815798 |