python - Pabot - 关闭浏览器后继续执行测试
问题描述
我现在正在使用Pabot成功运行并行机器人框架测试(如果您还没有,请检查一下)。目前,我正在同时运行两个简单的测试,包括使用两种不同类型的用户执行登录。我使用以下命令从命令行运行测试:
pabot --pabotlib --processes 2 --resourcefile valueset.dat --outputdir c:\pabot-demo\reports\ *.robot
一切顺利:浏览器打开,登录数据正确提交到表单,登录后主页出现,浏览器关闭。问题是,在那之后,我的终端进入了某种循环,并且执行在技术上似乎还没有完成:
Robot Framework remote server at 127.0.0.1:8270 started.
2018-10-16 15:58:38.109000 [PID:2144] [0] EXECUTING Suites.LoginAdmin
2018-10-16 15:58:38.109000 [PID:9736] [1] EXECUTING Suites.LoginUser
DevTools listening on ws://127.0.0.1:55688/devtools/browser/9bed6f8e-36c8-40b2-81f5-4622a4933c12
DevTools listening on ws://127.0.0.1:55689/devtools/browser/074fb0f2-5613-4483-9747-5b98eff98dcd
2018-10-16 15:58:53.853000 [PID:2144] [0] still running Suites.LoginAdmin after 15.0 seconds (next ping in 20.0 seconds)
2018-10-16 15:58:53.953000 [PID:9736] [1] still running Suites.LoginUser after 15.0 seconds (next ping in 20.0 seconds)
2018-10-16 15:59:15.693000 [PID:2144] [0] still running Suites.LoginAdmin after 35.0 seconds (next ping in 25.0 seconds)
2018-10-16 15:59:15.809000 [PID:9736] [1] still running Suites.LoginUser after 35.0 seconds (next ping in 25.0 seconds)
2018-10-16 15:59:43.321000 [PID:2144] [0] still running Suites.LoginAdmin after 60.0 seconds (next ping in 30.0 seconds)
2018-10-16 15:59:43.437000 [PID:9736] [1] still running Suites.LoginUser after 60.0 seconds (next ping in 30.0 seconds)
2018-10-16 16:00:16.330000 [PID:2144] [0] still running Suites.LoginAdmin after 90.0 seconds (next ping in 35.0 seconds)
2018-10-16 16:00:16.415000 [PID:9736] [1] still running Suites.LoginUser after 90.0 seconds (next ping in 35.0 seconds)
2018-10-16 16:00:55.144000 [PID:2144] [0] still running Suites.LoginAdmin after 125.0 seconds (next ping in 40.0 seconds)
2018-10-16 16:00:55.212000 [PID:9736] [1] still running Suites.LoginUser after 125.0 seconds (next ping in 40.0 seconds)
2018-10-16 16:01:39.360000 [PID:2144] [0] still running Suites.LoginAdmin after 165.0 seconds (next ping in 45.0 seconds)
2018-10-16 16:01:39.507000 [PID:9736] [1] still running Suites.LoginUser after 165.0 seconds (next ping in 45.0 seconds)
2018-10-16 16:02:29.098000 [PID:2144] [0] still running Suites.LoginAdmin after 210.0 seconds (next ping in 50.0 seconds)
2018-10-16 16:02:29.445000 [PID:9736] [1] still running Suites.LoginUser after 210.0 seconds (next ping in 50.0 seconds)
2018-10-16 16:02:31.716000 [PID:2144] [0] PASSED Suites.LoginAdmin in 212.3 seconds
2018-10-16 16:02:32.300000 [PID:9736] [1] PASSED Suites.LoginUser in 212.5 seconds
Output: c:\pabot-demo\reports\output.xml
Log: c:\pabot-demo\reports\log.html
Report: c:\pabot-demo\reports\report.html
Stopping PabotLib process
Robot Framework remote server at 127.0.0.1:8270 stopped.
PabotLib process stopped
Elapsed time: 3 minutes 54.904 seconds`
每次持续 3-4 分钟,然后自行停止。我的测试场景相当简单:
*** Settings ***
Documentation Tests login functionality
Library SeleniumLibrary
Library OperatingSystem
Library DateTime
Library Screenshot
Library pabot.PabotLib
Resource common.robot
Test Setup General Setup
Test Teardown End Scenario
*** Tags ***
Enduser
*** Keywords ***
End Scenario
Run Keyword If Test Failed Take Screenshot 01_LoginEnduserTest_FAILED_ScreenShot.png
Close Browser
General Setup
# CREATING THE DRIVER VARIABLE
Set Global Variable ${DRIVERNAME} Chrome
# CREATING THE SCREENSHOT DIRECTORY
Set Global Variable ${SCREENSHOTPATH} [a path]/target/robotframework-reports/${DRIVERNAME}
Create Directory ${SCREENSHOTPATH}
Set Screenshot Directory ${SCREENSHOTPATH}
# Getting the valueset
${valuesetname}= Acquire Value Set
# Opening the browser
Open Browser [the application's URL] Chrome
Maximize Browser Window
Location Should Contain [part of the application's URL]
*** Test Cases ***
Login
${username} = Get Value From Set username
${password} = Get Value From Set password
Input Text //input[@name='josso_username'] ${username}
Input Text //input[@name='josso_password'] ${password}
Click Element //input[@type='submit']
Wait Until Page Contains Dossier 60
Location Should Be [the application's URL]
Sleep 5s
当然,另一种情况是这种情况的一种变体。正常执行后,浏览器关闭,我必须等待 3 到 4 分钟才能停止 ping 消息并生成报告,如下所示:
看到潜在的未来发展(即,在我们目前缺乏资源的不同机器上运行测试),我正在使用 valueset.dat 文件来获取不同的用户名/密码组合。该文件的内容与我们在 Pabot 示例中看到的非常相似,但我还是可以包含它:
[Server1]
HOST=(my local IP)
USERNAME=system_admin
PASSWORD=1234
[Server2]
HOST=(my local IP)
USERNAME=system_user
PASSWORD=1234
知道如何让这个漫长的等待消失吗?是否有可能,当我向每个套件/更多套件添加更多测试时,这种等待将变得无关紧要?
编辑我正在使用以下设置:
Python 2.7.14
wxPython 2.8.12.1,win64,unicode,用于 py27
setuptools 40.2.0(允许我使用 easy_install 命令)
机器人框架 3.0.4
机器人远程服务器 1.1
Selenium2Library 3.0.0
和Pabot 版本 0.45。
另外,我的测试是针对 Chrome 运行的,所以我使用的是chromedriver 2.41。
解决方案
Test Teardown Close Browser
在测试套件的末尾尝试。
推荐阅读
- octave - Octave GUI 命令窗口 - 我可以增加显示的行数和列数吗?
- debugging - 如何在 VS Code 中调试 Neutralino?
- excel - 单元格中特殊字符之后/之前的粗体部分文本
- react-native - 如何将现有的 React Native App 升级到新的 React Native 版本?我们有任何文件吗?
- c++ - C++ 在调用 std::cin 之前删除任何先前的输入
- css - 如果某些数据为空或未定义,则使用 ngClass 更改组件的 CSS 类
- r - 如何使用命名列表有条件地按组切割数据集?
- spring-integration - 在单个应用程序中使用多个服务激活器
- json - 从当前目录引用 JSON 模式
- php - 显示从存储 laravel 上传的图像