Skip to content

me3eh/PB_Testing

Repository files navigation

PB TESTING

Library for testing using Page Object Pattern and Behaviour Driven Development.

Usage

This application is experimental and is used mainly for Engineer's Thesis.

It will be maintained for errors and probably in near future might get some new features.

Before using

Before creating any tests, you need geckodriver. It's crucial, because selenium, which is responsible for initializing the browser and doing actions, need this driver to work. Link for geckodriver: https://github.com/mozilla/geckodriver/releases.

There are several ways for preparing driver to coopearte with library, depending on Operating System. On each of systems: Microsoft Windows, macOS and Linux it looks a bit different. I was using Linux, so I will describe it here, but here are links for other OS:

Windows: http://www.learningaboutelectronics.com/Articles/How-to-install-geckodriver-Python-windows.php

macOS: https://medium.com/dropout-analytics/selenium-and-geckodriver-on-mac-b411dbfe61bc

On Linux you need to:

  • download driver,
  • unpack it with any tool,
  • set execute rights for user chmod 700,
  • put library on path /usr/local/bin. It can be done by moving it to location(mv), copying to location(cp) or linking to directory(ln). Each command will work <geckodriver_name> /usr/local/bin

It's worth mentioning that is not only working way to put geckodriver to work with selenium.

Commands

All commands are typed into terminal, using venv

To activate venv type command

source venv/bin/activate

It will look like this. venv will show up next to your name and command prompt source_venv.png


prepare

It will create:

  • directories: resources_for_testing, features, steps, pages
  • configuration_file config.ini
  • common_steps.py file in steps,`` consisting basic commands used in testing (selenium finding, clicking elements on site)
  • database for keeping urls from your project

This step is crucial, because it will setup all directoreies for using this library

Available frameworks for url scan: rails, django


pb_configuration

This method will pop gui with urls from your project and urls used in tests. It will look like this: how_pb_configuration_looks.png

On left we have urls scanned from project. On the right side there are urls that will be used in testing.

Between listboxes is arrow, which let user pass value from one listbox to another and at the bottom there are buttons, which also allow user to include new urls into testing.

Overall working: how_pb_configuration_works.png


step_creator

This gui is responsible for creating tests, using scanning urls and

OK, application is fine, but how to do testing?

Testing in this application is based on BDD. This means you need to write scenarios with them If you generate plan of actions, you will have an implementation of that keyword, but you also need to have scenario on which it will be executing tests. Example: scenario:

Feature: login as admin
  Scenario: with correct passes
    When logging in with username and password for admin
    Then user will be logged as admin and redirected to /admin

will be implemented by this code below, generated in app

from behave import *

@when ('logging in with username and password for admin')
def step(context):
	context.execute_steps(u'''
		When visiting site http://localhost:8000/
		When filling input with xpath
		 //input[@class='form-control' and @id='user-name'
		 and @name='username' and @type='text']
		 with text jar
		When filling input with xpath
		 //input[@class='form-control' and @id='user-password'
		 and @name='password' and @type='password']
		 with text jarjarjar
		When clicking on element with xpath
		 //input[@class='btn btn-xs btn-primary' and
		 @type='submit' and @value='Zaloguj']
	''')

@then ('user will be logged as admin and redirected to /admin')
def step(context):
	context.execute_steps(u'''
		Then it should have an url http://localhost:8000/admin/
	''')

Little story of usage step_creator 1.png 2.png 3.png you can save and load plans in application for later usage 4.png application give opportunity to generate plans and later use it in plan as normal action 5.png 6.png 7.png 8.png 9.png 10.png

Invoking tests Use command behave <name_of_feature_file>

About

Testowanie aplikacji przy użyciu wzorca Obiekt Strona i sposobu rozwoju oprogramowania BDD

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages