Ich wollte also datengesteuerte Tests mit Selen studieren Ich habe es mit py.test geschrieben, einem Testframework von Python.
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>/rot- Wikipedia"),
("Blau", "<em>Blau</em> - Wikipedia"),
("Gelb", "5-chome tausend<em>Gelb</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>/rot- Wikipedia] PASSED
pram_test.py:8: test_search[Blau-<em>Blau</em> - Wikipedia] PASSED
pram_test.py:8: test_search[Gelb-5-chome tausend<em>Gelb</em>] PASSED
======================================================== 3 passed in 13.50 seconds =========================================================