Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

ikostan/ParaBankSeleniumAutomation

Repository files navigation

Build Status License: Unlicense HitCount

Selenium (Python) Automation for Para Bank Web App

Table of Contents:

  1. About the project

  2. PARA BANK ParaSoft Demo App

  3. Official Documentation

  4. Dev Environment

  5. Tech Issues and Problem Solving

  6. Docs:

  7. Selenium Webdriver:

  8. Web Element

  9. Expected Results

  10. Page/Element Locators

  11. Page Object Model (POM)

  12. Tests

    i. Content Tests

    ii. End To End Tests

  13. Utils

About the project:

The main purpose is to demonstrate the professional abilities of writing browser automation using the Python language with Selenium.

Main Objectives:

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!

Official Documentation:

Parasoft Resources:

Additional Resources:

Dev Environment:

  1. Python 3.7.4
  2. Selenium 3.141.0
  3. PyTest 5.0.0
  4. Allure Framework 2.12.1
  5. Win 10 (64 bit)
  6. PyCharm 2019.2 (Community Edition)
  7. GitHub Desktop 2.1.0
  8. GIT 2.22.0.windows.1
  9. Java SE 8
  10. Scoop
  11. Parasoft Virtualize Community Edition

Python Packages:

Full list of dependencies see here.

Nice to have tools:

  1. Fiddler: The free web debugging proxy
  2. Kite: Code Faster in Python
  3. Ragnorex: Smart Selector Generator
  4. 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.

Supported/tested browsers:

  • Chrome: v75 (64 bit)
  • Firefox: v68 (64 bit)
  • Edge: v17 and above

Tech Issues and Problem Solving:

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
  1. open CMD
  2. navigate to project directory, for example:
cd C:\Users\superadmin\Desktop\Python\CodinGame
  1. run following command:
pip install virtualenv
  1. 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.

  1. Open Terminal
  2. Run: \path\to\env\Scripts\activate


Source: https://pypi.org/project/virtualenv/1.8.2/

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


- How to fix 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