Skip to content

Review create webdriver code and tests #1787

Open

Description

@emanlove

With the recent removal of the Opera references I noticed some discrepancies and some things that just didn't look right within this code. I want to review that code now there are some significant changes. This is a placeholder reminder.

Activity

  1. added this to the v6.1.0 milestone on Oct 5, 2022
  2. emanlove commented on Oct 5, 2022

    @emanlove
    MemberAuthor

    Also review for phantomJS, Andriod, and iPhone references as well

  3. emanlove commented on Oct 23, 2022

    @emanlove
    MemberAuthor

    Another item we should check is the parameters for creating webdriver. I see an additional parameter service on the Chrome and Chromium WebDriver classes that I am not sure we are either describing (very likely) or passing along (I think unlikely).

  4. simonmeggle commented on Dec 21, 2022

    @simonmeggle

    Hi Ed, I also notice that creating a webdriver does not work as expected (Selenium 4.7.2, SeleniumLibrary 6.0.0).

    # (The browser type does not really matter)
    Create Webdriver  chromium
    

    calls browsermanagement > BrowserManagementKeywords > create_webdriver

    driver_name = driver_name.strip()
    try:
    creation_func = getattr(webdriver, driver_name)
    except AttributeError:
    raise RuntimeError(f"'{driver_name}' is not a valid WebDriver name.")
    self.info(f"Creating an instance of the {driver_name} WebDriver.")
    driver = creation_func(**init_kwargs)
    self.debug(

    creation_func should return the browser specific webdriver class (instantiated in line 391), but all it returns is the module <module 'selenium.webdriver.chromium'>:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    TypeError: 'module' object is not callable
    

    (its __init__.py is empty, no code runs)

    However, while debugging, when I am assigning the Chromium Webdriver class by hand, creation_func starts the browser:

    # (halted in line 391) 
    from selenium.webdriver.chrome.webdriver import WebDriver
    creation_func = WebDriver
    creation_func(**init_kwargs)
    # (chromium starts successfully)
    <selenium.webdriver.chrome.webdriver.WebDriver (session="62a68ae2a4b6687ae0f76df8cc45883e")>
    

    I am far from being able to judge whether my approach is correct or to decide what exactly is the error.
    But yes, there is something broken (but you already knew that before ;-) )

  5. emanlove commented on Dec 21, 2022

    @emanlove
    MemberAuthor

    I wasn't aware of an issue this in depth. I just know that some recent changes in both Selenium and SeleniumLibrary around supported browsers and the underlying Open Browser keyword/functionality threw up red flags in my mind. So I wanted a full review. Thanks for this report!

  6. simonmeggle commented on Dec 21, 2022

    @simonmeggle

    OMG. Wrong path... 🤦‍♂️
    It makes a big difference how you write the browser name.

    creation_func = getattr(webdriver, driver_name)

    In case of "Chrome" it returns the webdriver object.
    But "chrome" is also an attribute of this module and returns the submodule (totally wrong).

    getattr(webdriver, "chrome")
    <module 'selenium.webdriver.chrome' from 'C:\\Program Files\\Python38\\lib\\site-packages\\selenium\\webdriver\\chrome\\__init__.py'>
    getattr(webdriver, "Chrome")
    <class 'selenium.webdriver.chrome.webdriver.WebDriver'>
    

    Maybe the first letter ofdriver_name should be forced to a capital letter before reading the attrs, so that "chrome" is also a valid argument?

    (EDIT: Sorry, has nothing to do with the actual problem now. )

  7. emanlove commented on Dec 21, 2022

    @emanlove
    MemberAuthor

    That looks like a usability bug to me. So I think it still counts!

    One of those robot improvements that's on my list would be situations like these where either a warning is given if it looks like someone has an invalid argument name. For example, Log console_msg=ed_was_here might result in Warning: Did you mean to use "console" argument instead of "console_msg" .. or something similar. There could also be the case you share where it is very close.

  8. modified the milestones: v6.1.0, V6.2.0 on Mar 29, 2023
  9. modified the milestones: v6.2.0, v6.3.0 on Nov 19, 2023
  10. modified the milestones: v6.3.0, April 2024 on Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions