|
| 1 | +from behave import * |
| 2 | +import subprocess |
| 3 | +import pexpect |
| 4 | + |
| 5 | +import unittest |
| 6 | +from selenium import webdriver |
| 7 | +from selenium.common.exceptions import TimeoutException |
| 8 | +from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0 |
| 9 | +from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0 |
| 10 | + |
| 11 | +driver = webdriver.PhantomJS() |
| 12 | + |
| 13 | +@given(u'a Ubuntu development machine') |
| 14 | +def step_impl(context): |
| 15 | + pass |
| 16 | + |
| 17 | +@given(u'nose is installed') |
| 18 | +def step_impl(context): |
| 19 | + pass |
| 20 | + |
| 21 | +@given(u'coverage is installed') |
| 22 | +def step_impl(context): |
| 23 | + pass |
| 24 | + |
| 25 | +@when(u'I execute "{cmd}"') |
| 26 | +def step_impl(context, cmd): |
| 27 | + out = execute(cmd) |
| 28 | + context.out = out |
| 29 | + |
| 30 | +@then(u'I should see "{expected_text}"') |
| 31 | +def step_impl(context, expected_text): |
| 32 | + assert expected_text in context.out |
| 33 | + |
| 34 | +def execute(cmd): |
| 35 | + output, status = pexpect.run(cmd |
| 36 | + , withexitstatus=1 |
| 37 | + , timeout=600 |
| 38 | + ) |
| 39 | + |
| 40 | + return output |
| 41 | + |
| 42 | +@given(u'I navigate to "{url}"') |
| 43 | +def step_impl(context, url): |
| 44 | + driver.get(url) |
| 45 | + |
| 46 | +@when(u'I search for "{keyword}"') |
| 47 | +def step_impl(context, keyword): |
| 48 | + inputElement = driver.find_element_by_name("q") |
| 49 | + inputElement.send_keys(keyword) |
| 50 | + inputElement.submit() |
| 51 | + context.driver = driver |
| 52 | + |
| 53 | +@then(u'I should see "{expected_text}" in the page title') |
| 54 | +def step_impl(context, expected_text): |
| 55 | + WebDriverWait(context.driver, 10).until(EC.title_contains(expected_text)) |
0 commit comments