I wanted to study data-driven testing with Selenium, so I wrote it using py.test, which is a python test framework.
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()
# 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