chromedriver不执行脚本,selenium测试结束时不打印任何结果

2024-06-26 01:35:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我在测试助手类中有这段代码

@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)

我在两个地方使用了相同的seccond代码段,它在第一种情况下有效,但在第二种情况下无效(WTF?)。第二次打开页面和对话框时,焦点甚至放在文本输入上,光标在其中,但文本没有写在那里(正如您在我的评论中所看到的,我以前在使用“no-execute\u script”方法时也遇到过问题

我运行这个的bash没有显示任何测试结果,但是已经准备好执行下一个命令,它告诉我测试脚本已经完成(好吧,至少它这么认为。)我甚至尝试从代码中打印作为调试的一种方式-没有结果

你知道为什么会这样吗?总的来说,你有没有一个更稳定的Chrome测试方法的想法?我觉得我已经准备好抛弃Webdriver了,因为它(几乎)只会带来挫败感,现在很难看出我从中得到了什么

如果出于某种原因您想查看更多文件,请在此处找到这些文件: https://github.com/thenakedthunder/flack/blob/reactify/flack/src/test/selenium/test_helper.pyhttps://github.com/thenakedthunder/flack/blob/reactify/flack/src/test/selenium/test_channel_view.py


Tags: the代码nametestinputexecutetimeis