Try out the touch of data-driven testing with Selenium Python Bindings and py.test

background

I wanted to study data-driven testing with Selenium, so I wrote it using py.test, which is a python test framework.

Script overview

pram_test.py


# -*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import pytest
import time

@pytest.mark.parametrize(("input", "expected"), [
    ("red", "<em>RED</em>/Red- Wikipedia"),
    ("Blue", "<em>Blue</em> - Wikipedia"),
    ("yellow", "5-chome thousand<em>yellow</em>"),
])

def test_search(input, expected):
    driver = webdriver.Chrome()
    driver.get("http://www.google.co.jp/")
    elem = driver.find_element_by_name("q")
    elem.send_keys(input)
    elem.send_keys(Keys.RETURN)
    time.sleep(1)
    assert expected in driver.page_source
    driver.close()

Test execution result

# py.test -v -s pram_test.py
=========================================================== test session starts ============================================================
platform darwin -- Python 3.3.3 -- pytest-2.5.1 -- /Users/hoge/local/py3/bin/python
collected 3 items 

pram_test.py:8: test_search[red-<em>RED</em>/Red- Wikipedia] PASSED
pram_test.py:8: test_search[Blue-<em>Blue</em> - Wikipedia] PASSED
pram_test.py:8: test_search[yellow-5-chome thousand<em>yellow</em>] PASSED

======================================================== 3 passed in 13.50 seconds =========================================================

Recommended Posts

Try out the touch of data-driven testing with Selenium Python Bindings and py.test
Try running Google Chrome with Python and Selenium
Install selenium on Mac and try it with python
I tried to automate the article update of Livedoor blog with Python and selenium.
Try scraping the data of COVID-19 in Tokyo with Python
Try hitting the Twitter API quickly and easily with Python
Let's touch the API of Netatmo Weather Station with Python. #Python #Netatmo
Try to automate the operation of network devices with Python
Play with the password mechanism of GitHub Webhook and Python
The story of Python and the story of NaN
Scraping with Python, Selenium and Chromedriver
Coexistence of Python2 and 3 with CircleCI (1.0)
I compared the speed of Hash with Topaz, Ruby and Python
Get and set the value of the dropdown menu using Python and Selenium
Practical edition of automating the testing of Flutter apps with Appium (Python)
Operate Firefox with Selenium from python and save the screen capture
Get the width of the div on the server side with Selenium + PhantomJS + Python
I replaced the numerical calculation of Python with Rust and compared the speed
Put Cabocha 0.68 on Windows and try to analyze the dependency with Python
Calculate the shortest route of a graph with Dijkstra's algorithm and Python
Check the existence of the file with python
[Python] Try pydash of the Python version of lodash
Find the general terms of the Tribonacci sequence with linear algebra and Python
The story of making a sound camera with Touch Designer and ReSpeaker
Get the number of articles accessed and likes with Qiita API + Python
[Completed version] Try to find out the number of residents in the town from the address list with Python
[Python] Automatically operate the browser with Selenium
Practice web scraping with Python and Selenium
Get and estimate the shape of the head using Dlib and OpenCV with python
I measured the speed of list comprehension, for and while with python2.7.
Touch AWS with Serverless Framework and Python
Try to separate the background and moving object of the video with OpenCV
Let's play with Python Receive and save / display the text of the input form
Get the stock price of a Japanese company with Python and make a graph
Create a clean DB for testing with FastAPI and unittest the API with pytest
[Python] Visualize and identify slow parts with pytest
Prepare the execution environment of Python3 with Docker
Automatic operation of Chrome with Python + Selenium + pandas
Summary of the differences between PHP and Python
2016 The University of Tokyo Mathematics Solved with Python
[Note] Export the html of the site with python.
Try to solve the man-machine chart with Python
Calculate the total number of combinations with python
Specifying the range of ruby and python arrays
Check the date of the flag duty with Python
Compare the speed of Python append and map
Try the free version of Progate [Python I]
Drag and drop local files with Selenium (Python)
Implementation of TRIE tree with Python and LOUDS
Solving the Lorenz 96 model with Julia and Python
Try using the collections module (ChainMap) of python3
Find out the day of the week with datetime
Archive and compress the entire directory with python
Convert the character code of the file with Python3
About the * (asterisk) argument of python (and itertools.starmap)
A discussion of the strengths and weaknesses of Python
Continuation of multi-platform development with Electron and Python
[Python] Determine the type of iris with SVM
Example of reading and writing CSV with Python
An introduction to cross-platform GUI software made with Python / Tkinter! (And many Try and Error)! (In the middle of writing)
Build API server for checking the operation of front implementation with python3 and Flask