diff --git a/features/00_web_test.feature b/features/00_web_test.feature deleted file mode 100644 index 5458335..0000000 --- a/features/00_web_test.feature +++ /dev/null @@ -1,8 +0,0 @@ -Feature: 检索测试 - - Scenario: 访问百度并搜索关键字 - Given 打开浏览器 - Then 访问"https://www.baidu.com" - And 输入关键字"土豆" - Then 确认进入了查询结果页面 - \ No newline at end of file diff --git a/features/baidu.feature b/features/baidu.feature new file mode 100644 index 0000000..17b10ce --- /dev/null +++ b/features/baidu.feature @@ -0,0 +1,9 @@ +Feature: 百度搜索 + + Scenario: 搜索关键词 + Given 关键词 behave + When 打开百度页面 + Then 输入关键词 + Then 点击百度一下按钮 + Then 页面标题中应包含关键词 + Then 关闭浏览器 diff --git a/features/steps/web_test.py b/features/steps/web_test.py index 040214c..c1b60c3 100644 --- a/features/steps/web_test.py +++ b/features/steps/web_test.py @@ -7,23 +7,27 @@ def step_impl(context, keyword): # context是上下文对象,有参数的话 context.keyword = keyword # 将参数绑定上下文对象,以便其他步骤使用 @when('打开百度页面') -def step_impl(context): - context.driver = driver = webdriver.Chrome() # 同样绑定上下文对象 +def step_imp2(context): + context.driver = driver = webdriver.Firefox() # 同样绑定上下文对象 driver.implicitly_wait(10) driver.get('https://www.baidu.com') -@when('输入关键词') -def step_impl(context): +@then('输入关键词') +def step_imp3(context): context.driver.find_element('id', 'kw').send_keys(context.keyword) -@when('点击百度一下按钮') -def step_impl(context): +@then('点击百度一下按钮') +def step_imp4(context): context.driver.find_element('id', 'su').click() - sleep(0.5) + sleep(2) @then('页面标题中应包含关键词') -def step_impl(context): - assert context.keyword in context.driver.title \ No newline at end of file +def step_imp5(context): + assert context.keyword in context.driver.title + +@then('关闭浏览器') +def step_imp6(context): + context.driver.quit() diff --git a/start_vscode.bat b/start_vscode.bat new file mode 100644 index 0000000..f41bc1c --- /dev/null +++ b/start_vscode.bat @@ -0,0 +1,6 @@ + +set PROJECT_HOME=%~dp0 + + +rem 确保vscode在path里面 +start code %PROJECT_HOME%