knowledge is power

Selenium

With Docker you can quickly and easily install, configure and use Selenium Grid. This tutorial shows the respective steps that you need as a software tester (or Developer). Instead of Python you can also use other languages, which are supported by Selenium​.

DDT (Data-driven Testing) with Python Selenium Webdriver is very easy! DDT becomes very useful if you have test cases that contains the same test steps. All values could outsourced into files or databases. This tutorial use CSV files.

Precondition

Python installed

selenium and ddt library installed

Example

The folder structure for this tutorial looks like:

1

2

3

4

5

6

7

8

9

├──data

│ └──scenario_a.csv

├──library

│ ├──GetData.py

│ └──__init__.py

├──scenarios

│ ├──__init__.py

│ └──scenario_a.py

└──testsuite.py

Into folder “data” we store the csv files. The packages “library” include a function to read the specific csv files and the package “scenarios” include the test cases. The test suite is on root folder.

testsuite.py

Python

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

#!/usr/bin/env python

# -*- coding: utf8 -*-

importunittest

fromscenarios.scenario_a importTestScenarioA

# load test cases

scenario_a=unittest.TestLoader().loadTestsFromTestCase(TestScenarioA)

# create test suite

test_suite=unittest.TestSuite([scenario_a])

# execute test suite

unittest.TextTestRunner(verbosity=2).run(test_suite)

Into the “testsuite.py” we add all test cases provided by scenario package.

data folder

scenario_a.csv

1

2

3

4

5

target_url,elem_name,search_value

http://softwaretester.info,s,python

http://softwaretester.info,s,selenium

http://softwaretester.info,s,webdriver

http://softwaretester.info,s,automation

The CSV stores the test data that we supplied to the @data decorator of test case.

You are done with your work and push all into Git. The Build-Server starts his work and all test scripts are failing. Short look and it is clear – certificate errors. The next example shows, how to ignore certificate errors on PhantomJS.