dimanche 17 novembre 2019

chromedriver does not execute script, selenium test finishes with no results printed out

I have this code in a test helper class

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

And I have this code that uses the one above:

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

I use this VERY SAME seccond snippet at two places, and it works in the first case, but doesn't in the second (WTF?). The second time it opens up the page and the dialog, the focus is even on the text input, the cursor in it, but the text is not written there. (As you can see in my comments, I had problems before with the "no-execute_script" approach too).

The bash I run this from does not show any test results as it should, but is ready to take the next command, which tells me the test script is finished (well, at least it thinks so.)

Do you have any idea why this happens? And generally speaking, do you have any idea for a stabler approach for testing in Chrome? I feel I am ready to dump Webdriver, since it caused (almost) only frustration, and it's hard to see what I gained with it now.

The files are to be found here, if for some reason you would like to see more of them: 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

Aucun commentaire:

Enregistrer un commentaire