Skip to content

Unify "index" type of keyword arguments. #1799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Unify "index" type of keyword arguments. #1799

wants to merge 1 commit into from

Conversation

rasjani
Copy link
Contributor

@rasjani rasjani commented Oct 12, 2022

create_webdriver was marked as returning a str, however, its return value is coming from register_driver which is documented to return int. These where changed to return actual int.

switch_driver was only accepting str as "index_or_alias". While aliases are str's since create_driver now returns the actual index as int, accepting both types makes more sense.

select and unselect list keywords where typehinted to receive only str as index type - when called from python side, this does not make much sense so changed those to int as RF should do type conversion automatically.

Fixes #1791

@rasjani rasjani requested a review from emanlove October 12, 2022 15:05
@rasjani
Copy link
Contributor Author

rasjani commented Oct 12, 2022

no tests have been written nor executed ..

create_webdriver was marked as returning a str, however, its return
value is coming from register_driver which is documented to return int.
These where changed to return actual int.

switch_driver was only accepting str as "index_or_alias". While aliases
are str's since create_driver now returns the actual index as int,
accepting both types makes more sense.

select and unselect list keywords where typehinted to receive only str
as index type - when called from python side, this does not make much
sense so changed those to int as RF should do type conversion
automatically.

Fixes #1791
@emanlove
Copy link
Member

emanlove commented Oct 13, 2022

One overarching thought is I would want this to be backwards compatible. Such that this change does not force people to change all their select from list by index calls. So I would want the Robot Type conversion from the robot side to take those strings and automatically convert those to ints in all cases that switch from incoming str to incoming int.

Adding some inline comments as well ..

@@ -133,7 +133,7 @@ class SeleniumLibrary:
def select_all_from_list(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str]): ...
def select_checkbox(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str]): ...
def select_frame(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str]): ...
def select_from_list_by_index(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str], *indexes: str): ...
def select_from_list_by_index(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str], *indexes: int): ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be Union[str, int] for Robot to do the type conversion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if robot core does not do the type conversion I would be fine with both

Union[str, int] as the argument type and then inrternally in all spots needed, something like

if isinstance(indexes, str):
    int(indexes)

.. although now I see these can be and are *indexes and not index, meaning it could be multiple indexes .. thus complicating my conversion strategy a bit ..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Noting these comments apply to all instances of these str to ints]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corner cases are not know but rf will do type conversion to int

Union is used only for with alias_or_index because alias is user defined string bu index is int returned by create_driver and register_driver

@rasjani rasjani requested a review from pekkaklarck October 13, 2022 12:21
@pekkaklarck
Copy link
Member

Don't have time to review this right now, but I have one possible idea related to this. We recently changed Robot's Process library to return actual process objects, not handles (e.g. ints), and it has worked great. Could Create Webdriver return the created WebDriver instance as well?

@rasjani rasjani closed this Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typing issues when using SeleniumLibrary directly from python.
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy