Keyword driven automation for the web
Project description
Keyword based test automation for the web.
Table of Contents
Introduction
QWeb is a powerful and versatile Robot Framework library that enables efficient and reliable web testing and automation. One of the key strengths of QWeb is its intuitive and user-friendly syntax, which makes it easy to write and maintain complex test cases.
QWeb aims to make web automation easy and maintainable by:
- providing an intuitive and user-friendly syntax for writing and maintaining complex test cases.
- providing smart locators: finding elements by text or by any attribute value with a simple syntax
- automatically handling latencies etc. via automatic wait times
- automatically handling frames
- automatically handling unexpected alerts
- providing support for finding shadow dom elements with an easy syntax
- providing in-built bitmap comparison for special cases where element can't be identified by any other means
- being technology agnostic and providing extensive support for various web technologies/frameworks
See examples.
Requirements
Python 3.9-3.12 and Robot Framework 4.1.3 or above.
(Note that support on Macs with Apple based silicon (M1) requires MacOS version 12/Monterey or above or custom installation.)
Installation
Windows
pip install QWeb
Linux/Mac
python3 -m pip install -U pip
python3 -m pip install QWeb
Running the above command installs also supported Selenium and Robot Framework versions + other dependencies.
Automatic browser & driver management
Since Selenium 4.10.0 browser drivers
can be automatically downloaded and installed using Selenium Manager, provided that driver is not found in PATH.
For Chrome browser_version
can also be given; if your locally installed Chrome matches this version,
it will be used. If not, a suitable version of Chrome for Testing
will be automatically downloaded.
Examples in OpenBrowser keyword documentation
Manual driver management
For manual installation of drivers, please refer to Selenium documentation for more information OR use 3rd party packages like WebDriverManager.
Usage
Keyword documentation
See list of keywords and their usage on
Examples
Basic usage
The preferred way to interact with web elements is using their text property. Most elements like input fields and dropdowns can also be found by closest label (text).
*** Settings ***
Library QWeb # Import library
*** Test Cases ***
Basic interaction
OpenBrowser https://qentinelqi.github.io/shop chrome # Open chrome and goto given url
VerifyText The animal friendly clothing company # Assert heading text
ClickText Scar the Lion # Click link text
ClickText Add to cart # Click *button* with specific text
DropDown Size Large # Select value (Large) from dropdown (Size)
Shadow DOMs and visibility
Most common cases when text or element is not found are:
- Element has (incorrectly?) some attribute set so, that it's considered invisible.
- Element is under shadow dom (i.e. has #shadow-root parent element)
QWeb searches for visible elements by default, but can be instructed to work with invisible elements as well. See keyword documentation of SetConfig and the following parameters:
- Visibility
- Offsetcheck
- InViewport
Elements under shadow DOM can not be found using xpaths. However, all *Text, *Item and *Input keywords do support extending the search to Shadow DOM elements. We intentionally keep this under separate setting for ensuring compatibility with older test cases.
Example:
*** Settings ***
Library QWeb # Import library
*** Test Cases ***
Click shadow dom element
SetConfig ShadowDOM True # extends search to shadow dom elements
OpenBrowser chrome://settings/content/popups chrome
ClickText Sites can send pop-ups
Timeouts and anchors
By default QWeb tries to locate the element 10 seconds (default time can be configured). Timeout can also be individually given for each keyword as an argument.
When text to be found is not unique, an 'anchor' argument can be given to pinpoint which instance of text we want to interact with. Anchor can be either another text nearby or index.
ClickText Sign-in
ClickText Sign-in timeout=30
ClickText Sign-in anchor=Email
ClickText Sign-in index=3
Other locators
Non-textual locators can be used with ClickElement
and ClickItem
keywords.
ClickElement xpath\=//button[@class="my_class"] # xpath
ClickItem Increment quantity # alt text
Working with tables
QWeb includes keywords to interact with table data easily.
Consider the following table as an example:
UseTable Firstname
${row}= GetTableRow //last # returns 5
${row}= GetTableRow //last skip_header=True # returns 4
...
${row}= GetTableRow Jim # returns 4
${row}= GetTableRow Jim skip_header=True # returns 3
${cell_value}= GetCellText r1c2 # Returns "John", first name is column 2.
${cell_value}= GetCellText r-1/c2 # Returns "Tina", -1 points to last row
${cell_value}= GetCellText r-2/c2 # Returns "Jim", -2 points to second last row
Changing configuration
QWeb's behavior can be changed with SetConfig keyword.
SetConfig SearchMode Draw # Highlight all found elements with blue rectangle
SetConfig DefaultTimeout 60s # change default/automatic timeout for all keywords
VerifyText User account created # Re-tries to find text "User account created" 60 seconds and then fails, if text is not visible
Running with Python
QWeb can be used directly with Python as well.
from QWeb import QWeb
qweb = QWeb()
qweb.open_browser("about:blank", "chrome")
qweb.go_to("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select")
title = qweb.get_title()
# returns 'W3Schools Tryit Editor'
qweb.verify_text("The select element")
qweb.drop_down("Choose a car", "Saab")
qweb.click_text("Submit")
qweb.verify_text("Your input was received as:")
qweb.verify_text("cars=saab")
More examples on QWeb tutorial.
Changelog
See RELEASE.md
Contribute
Found an bug? Want to propose a new feature or improve documentation? Please start by checking our contribution guide
Community
Want to join the community at Slack? On the official Robot Framework workspace, there is a QWeb channel where you can discuss with others about keywords, issues and improvements. Join Now
License
Apache 2.0 License. See LICENSE.
Resources
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
File details
Details for the file qweb-3.4.2.tar.gz
.
File metadata
- Download URL: qweb-3.4.2.tar.gz
- Upload date:
- Size: 170.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05bfb9a593a0a238f13c418d5c546fcfb142474393952029a90703a3cf0c3e21 |
|
MD5 | 4bba6ce61d0b65241113ec71a67691d4 |
|
BLAKE2b-256 | 3e1e07206d96750c208009f86453124c8f0422804ec6a135b3d44e2ee1e6a0fb |
File details
Details for the file QWeb-3.4.2-py3-none-any.whl
.
File metadata
- Download URL: QWeb-3.4.2-py3-none-any.whl
- Upload date:
- Size: 203.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce2e4b036aa7616bcb38afba6fde9ea478f430fa3a7e083fe64f5d9cebedcfde |
|
MD5 | f41c9530d073083f286216d8cf982216 |
|
BLAKE2b-256 | 9b5be99e31d57ad7be06f432677e69334a697fe93eae06a0fafb414afde887c7 |