-
Docs:
-
ii. End To End Tests
The main purpose is to demonstrate the professional abilities of writing browser automation using the Python language with Selenium.
Main Objectives:
- Build fast and readable automation using minimal code
- Showcase with effective way to identify web elements
- Page Objects and Element Objects implementation (see Page Object Model (POM) and Element Object)
- Arrange, Act and Assert (AAA) Pattern implementation (see step_definition)
- Industry-ready test structure
- Cross-browsing testing (see Config class and get_args_from_cli file)
- Ability to pass arguments from CLI (see get_args_from_cli file)
- Build readable test report using Allure Framework
- Test code should avoid violating principles like DRY, YAGNI, SRP and KISS.
- Integration with Travis CI
- Using real-like web app (ParaBank Demo Web App) in order to accomplish all the above
ParaBank is a demo site used for demonstration of Parasoft software solutions.
All materials herein are used solely for simulating a realistic online banking website.
In other words: ParaBank is not a real bank!
Parasoft Resources:
- Demo Website
- Read more about Para Bank demo website available services
- The ParaBank demo application from Parasoft
- Parasoft Virtualize Community Edition
- 'SOAtest & Virtualize' System Requirements
- SOAtest Desktop Installation
- Video: how to install Parasoft 'SOAtest & Virtualize' software
- Setting Up ParaBank
- How To Videos
- SOAtest Videos
- API Testing How-to Videos
- FAQs
- Parasoft Documentation and Resources
Additional Resources:
- Selenium Documentation
- Full Pytest documentation
- 'Selenium with Python' official documentation webpage
- PyCharm - Manage dependencies using requirements.txt
- Allure Framework
- Python 3.7.4
- Selenium 3.141.0
- PyTest 5.0.0
- Allure Framework 2.12.1
- Win 10 (64 bit)
- PyCharm 2019.2 (Community Edition)
- GitHub Desktop 2.1.0
- GIT 2.22.0.windows.1
- Java SE 8
- Scoop
- Parasoft Virtualize Community Edition
Full list of dependencies see here.
- Fiddler: The free web debugging proxy
- Kite: Code Faster in Python
- Ragnorex: Smart Selector Generator
- Pynsource: Python source code into UML diagrams
Note: In order to instantiate webdriver I use Driver class of my own. For more info please look here.
- Chrome: v75 (64 bit)
- Firefox: v68 (64 bit)
- Edge: v17 and above
Changing the project interpreter in the PyCharm project settings
1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Project | Project Interpreter.
2. Expand the list of the available interpreters and click the Show All link.
3. Select the target interpreter. When PyCharm stops supporting any of the outdated Python versions, the corresponding project interpreter is marked as unsupported.
4. The Python interpreter name specified in the Name field, becomes visible in the list of available interpreters. Click OK to apply the changes.
For more info please check here
PyCharm - Choosing Your Testing Framework
1. Open the Settings/Preferences dialog, and under the node Tools, click the page Python Integrated Tools.
2. On this page, click the Default Test Runner field.
3. Choose the desired test runner:
For more info please see Enable Pytest for you project
Setting up Python3 virtual environment on Windows machine
- open CMD
- navigate to project directory, for example:
cd C:\Users\superadmin\Desktop\Python\CodinGame
- run following command:
pip install virtualenv
- run following command:
virtualenv venv --python=python
Activate Virtual Environment
In a newly created virtualenv there will be a bin/activate shell script. For Windows systems, activation scripts are provided for CMD.exe and Powershell.
- Open Terminal
- Run: \path\to\env\Scripts\activate
Auto generate requirements.txt
Any application typically has a set of dependencies that are required for that application to work. The requirements file is a way to specify and install specific set of package dependencies at once.
Use pip’s freeze command to generate a requirements.txt file for your project:
pip freeze > requirements.txt
If you save this in requirements.txt, you can follow this guide: PyCharm - Manage dependencies using requirements.txt, or you can:
pip install -r requirements.txt
Source: https://www.idiotinside.com/2015/05/10/python-auto-generate-requirements-txt/
How to fix in case .gitignore is ignored by Git
Even if you haven't tracked the files so far, Git seems to be able to "know" about them even after you add them to .gitignore.
NOTE:
- First commit your current changes, or you will lose them.
- Then run the following commands from the top folder of your Git repository:
git rm -r --cached .
git add .
git commit -m "fixed untracked files"
Common Selenium errors
Microsoft webdriver for edge 18 and above
MS made WebDriver a Windows Feature on Demand (FoD), which ensures that it’s always up to date automatically, and enables some new ways to get Microsoft WebDriver.
The simplest way to get started is simply to enable Developer Mode. Simply open the Settings app and go to “Update & Security,” “For developers,” and select “Developer Mode.” The appropriate version of WebDriver will be automatically installed.
You can also install a standalone version of WebDriver in one of two ways:
* Search “Manage optional features” from Start, then select “Add a Feature,” “WebDriver.”
* Install via DISM by running the following command in an elevated command prompt:
DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
This also means that MS will no longer be providing standalone downloads for Microsoft WebDriver going forward
Source: https://blogs.windows.com/msedgedev/2018/06/14/webdriver-w3c-recommendation-feature-on-demand/#Rg8g2hRfjBQQVRXy.97
Test are failed due to slow performance of WebDriver
Explicit wait is used to specify wait condition for a particular element.
Here we define to wait for a certain condition to occur before proceeding further in the code.
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
# Wait for element to appear:
wait = WebDriverWait(self.driver, 10)
wait.until(ec.title_is(self.new_window_name))
How to Get Selenium to Wait for Page Load After a Click
It turns out Selenium has a built-in condition called staleness_of, as well as its own wait-for implementation.
Use them, alongside the @contextmanager decorator and the magical-but-slightly-scary yield keyword, and you get:
from contextlib import contextmanager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import staleness_of
class MySeleniumTest(SomeFunctionalTestClass):
# assumes self.browser is a selenium webdriver
@contextmanager
def wait_for_page_load(self, timeout=30):
old_page = self.browser.find_element_by_tag_name('html')
yield
WebDriverWait(self.browser, timeout).until(
staleness_of(old_page)
)
def test_stuff(self):
# example use
with self.wait_for_page_load(timeout=10):
self.browser.find_element_by_link_text('a link')
Note that this solution only works for “non-JavaScript” clicks, i.e., clicks that will cause the browser to load a brand new page, and thus load a brand new HTML body element.
Source: https://blog.codeship.com/get-selenium-to-wait-for-page-load/
error: RPC failed; curl 56 Recv failure: Connection was reset
1. Open Git Bash
2. Run: "git config --global http.postBuffer 157286400"
Source: https://stackoverflow.com/questions/36940425/gitlab-push-failed-error