Getting Started in Testing Automation

gkzz
4 min readFeb 11, 2019

I have decided to grasp overview of implemention testing and bought “Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and JavaScript 2nd Edition”.

This book is high recommended by Python community on Facebook.

I tried to implement testing with Python, Django, and Selenium.

Demo to run my first testing program

Here is my first testing code.

import sys
import os
import time
from selenium import webdriver
#####################################################################CONST
LOCAL_HOST_URL = ‘http://<localhost e.g. 127.0.0.1>:8000/'
GOOGLE_URL = ‘https://www.google.com/'
#As WSL is my local development, I put chromedriver under <my project name>/install/
EXECUTABLE_PATH =’/mnt/c/<your project name>/install/chromedriver.exe’
####################################################################driver = webdriver.Chrome(executable_path=EXECUTABLE_PATH)#driver.get(GOOGLE_URL)
driver.get(LOCAL_HOST_URL)
time.sleep(5)
#print(driver.title)
#assert ‘Welcome to Django’ in driver.title
assert 'Hello World!' in driver.title, "driver.title: " + driver.title"""Traceback (most recent call last):File "test01_assert_driver_title.py", line 40, in <module>assert 'Hello World!' in driver.title, "driver.title: " + driver.titleAssertionError: driver.title: Welcome to Django"""driver.quit()

If you want to see the updated code, please look at here!

Chrome’s info is annoying for me, so that I rewrote my code.

How “ Chrome is being controlled by automated test software” is Displayed?

Q. How to install chromedriver under WSL?

A. My procedure is bellow;

$ mkdir -p <your project name>/install
$ cd <your project name>/install
$ wget https://chromedriver.storage.googleapis.com/2.46/chromedriver_win32.zip
$ unzip chromedriver_win32.zip
#If you get the error that The program 'unzip' is currently not installed., please type the commands bellow. After that, try again!
#sudo apt install -y unzip
#unzip chromedriver_win32.zip
$ sudo rm chromedriver_win32.zip

sources;

【Python】Windows Subsystem for LinuxでSelenium環境を整える

cf. The URL I downloaded ChromeDriver

ChromeDriver — WebDriver for Chrome

cf. Where to find 64 bit version of chromedriver.exe for Selenium WebDriver?

There is no separate 64-bit version of Chromedriver. The version available at https://sites.google.com/a/chromium.org/chromedriver/downloads works on both 32 and 64-bit Windows, against either 32-or 64-bit Chrome.

Frameworks, Tools I used

$ cat requirements.txt
Django==1.11.8
pkg-resources==0.0.0
pytz==2018.9
selenium==3.141.0
urllib3==1.24.1
$ ls -la install/chromedriver.exe-rwxrwxrwx 1 foo foo 8627712 Feb 1 11:09 chromedriver.exe$ ls -la /usr/bin /chromium-browser
-rwxr-xr-x 1 root root 7134 Dec 15 04:49 /usr/bin/chromium-browser

*------------------ Updated in 11th, Feb, 2019 ----------------*
There is Google Chrome under my Windows 10, so that I don't need to install "chromium".
Actually, my first testing program works after I remove it.

Python and Ubuntu Version

$ python --version
Python 3.6.5
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.5 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.5 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

cf. What kind of book is “Obey the Testing Goat:”?

These sentences bellow are description of it sited on Amazon;

By taking you through the development of a real web application from beginning to end, the second edition of this hands-on guide demonstrates the practical advantages of test-driven development (TDD) with Python. You’ll learn how to write and run tests before building each part of your app, and then develop the minimum amount of code required to pass those tests. The result? Clean code that works.

In the process, you’ll learn the basics of Django, Selenium, Git, jQuery, and Mock, along with current web development techniques. If you’re ready to take your Python skills to the next level, this book — updated for Python 3.6 — clearly demonstrates how TDD encourages simple designs and inspires confidence.

・ Dive into the TDD workflow, including the unit test/code cycle and refactoring

・Use unit tests for classes and functions, and functional tests for user interactions within the browser

・Learn when and how to use mock objects, and the pros and cons of isolated vs. integrated tests

・Test and automate your deployments with a staging server

・Apply tests to the third-party plugins you integrate into your site

・Run tests automatically by using a Continuous Integration environment

・Use TDD to build a REST API with a front-end Ajax interface

Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and JavaScript (English Edition) 2nd Edition

Here is my source code.

--

--

gkzz

🇯🇵 #SoftwareDeveloper #MeijiUniv @apc_tweet Opinions are my own. #Geek #ギークハウス大倉山 #gkz https://gkzz.github.io/