首页 > 解决方案 > 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 _ _

标签: pythonseleniumtestingselenium-chromedriver

解决方案


推荐阅读