python - chromedriver 不执行脚本,硒测试完成,没有打印出结果
问题描述
我在测试助手类中有这段代码
@staticmethod
def setup_with_new_displayname():
""" Sets the application up for tests. 'execute_script' functions had
to be called as a workaround because issues with the webdriver ones
"""
time.sleep(5)
# the next line is where I have the problem:
TestHelper.driver.execute_script(
"document.querySelector('#displayname-input').value = 'gecó '")
TestHelper.driver.find_element_by_id("displayname-input").send_keys(
Keys.BACKSPACE) #Workaround for the field to notice input
# clicks the "Use this name" button
time.sleep(1) # otherwise the button is not always found
TestHelper.driver.execute_script(
"document.querySelector('#display-name-ok-btn').click()")
我有这段代码使用上面的代码:
@classmethod
def setUpClass(cls):
""" Get the display name prompt out of the way
(it is tested in test_display_name_dialog.py)
"""
TestHelper.setup_with_new_displayname()
time.sleep(3)
我在两个地方使用了这个非常相同的第二个片段,它在第一种情况下有效,但在第二种情况下不起作用(WTF?)。第二次打开页面和对话框时,焦点甚至在文本输入上,光标在其中,但文本没有写在那里。(正如您在我的评论中看到的那样,我之前也遇到过“no-execute_script”方法的问题)。
我运行它的 bash 没有显示任何应有的测试结果,但已准备好执行下一个命令,该命令告诉我测试脚本已完成(好吧,至少它是这样认为的。)我什至尝试从代码作为一种调试方式 - 没有结果。
你知道为什么会这样吗?一般来说,您对在 Chrome 中进行更稳定的测试方法有任何想法吗?我觉得我已经准备好抛弃 Webdriver,因为它(几乎)只造成了挫败感,而且现在很难看出我从中获得了什么。
这些文件可以在这里找到,如果出于某种原因您想查看更多文件: https : //github.com/thenakedthunder/flack/blob/reactify/flack/src/test/selenium/test_helper.py https: //github.com/thenakedthunder/flack/blob/reactify/flack/src/test/selenium/test_channel_view.py _ _
解决方案
推荐阅读
- xcode - 安装 cocoapods 对项目有何影响?
- php - Laravel 雄辩的高级 where 子句:未定义的变量 | 我使用 use()
- c# - 用于统一网格绑定的 DataTemplateSelector?
- sql - 将不同的值和计算字段从一个表插入到另一个表
- git - 如何等待 Jenkins 作业进行多个 git commit 然后开始作业
- java - 如何将嵌套或 JSON 对象保存在 spark 数据集中并转换为 RDD?
- c++ - 将私有对象变量与用户输入的变量进行比较
- c++ - 无法为在 neovim 中运行的程序提供输入
- java - 如何在 windowslistener 方法中调用 JFrame(类本身)?
- javascript - 当 validateFields 调用时,记录 2 个错误,当数据无效时(React,Antd)