From 8f647ef84e72fb47b4b6fb223cecf20019a2fea3 Mon Sep 17 00:00:00 2001 From: Simon Benzer Date: Sun, 12 Jan 2025 13:44:27 -0500 Subject: [PATCH 1/8] [py] Added Docstrings to ActionBuilder --- .../common/actions/action_builder.py | 91 ++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/py/selenium/webdriver/common/actions/action_builder.py b/py/selenium/webdriver/common/actions/action_builder.py index 63bfe6db57a34..d535a7266658d 100644 --- a/py/selenium/webdriver/common/actions/action_builder.py +++ b/py/selenium/webdriver/common/actions/action_builder.py @@ -49,6 +49,17 @@ def __init__( self.driver = driver def get_device_with(self, name: str) -> Optional[Union["WheelInput", "PointerInput", "KeyInput"]]: + """Get the device with the given name. + + Parameters: + ---------- + name : str + The name of the device to get. + + Returns: + -------- + Optional[Union[WheelInput, PointerInput, KeyInput]] : The device with the given name. + """ return next(filter(lambda x: x == name, self.devices), None) @property @@ -72,21 +83,83 @@ def wheel_action(self) -> WheelActions: return self._wheel_action def add_key_input(self, name: str) -> KeyInput: + """Add a new key input device to the action builder. + + Parameters: + ---------- + name : str + The name of the key input device. + + Returns: + -------- + KeyInput : The newly created key input device. + + Example: + -------- + >>> action_builder = ActionBuilder(driver) + >>> action_builder.add_key_input(name="keyboard2") + """ new_input = KeyInput(name) self._add_input(new_input) return new_input def add_pointer_input(self, kind: str, name: str) -> PointerInput: + """Add a new pointer input device to the action builder. + + Parameters: + ---------- + kind : str + The kind of pointer input device. + - "mouse" + - "touch" + - "pen" + name : str + The name of the pointer input device. + + Returns: + -------- + PointerInput : The newly created pointer input device. + + Example: + -------- + >>> action_builder = ActionBuilder(driver) + >>> action_builder.add_pointer_input(kind="mouse", name="mouse") + """ new_input = PointerInput(kind, name) self._add_input(new_input) return new_input def add_wheel_input(self, name: str) -> WheelInput: + """Add a new wheel input device to the action builder. + + Parameters: + ---------- + name : str + The name of the wheel input device. + + Returns: + -------- + WheelInput : The newly created wheel input device. + + Example: + -------- + >>> action_builder = ActionBuilder(driver) + >>> action_builder.add_wheel_input(name="wheel2") + """ new_input = WheelInput(name) self._add_input(new_input) return new_input def perform(self) -> None: + """Performs all stored actions. + + Example: + -------- + >>> action_builder = ActionBuilder(driver) + >>> keyboard = action_builder.key_input + >>> el = driver.find_element(id: "some_id") + >>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys('keys').perform + """ enc = {"actions": []} for device in self.devices: encoded = device.encode() @@ -96,8 +169,24 @@ def perform(self) -> None: self.driver.execute(Command.W3C_ACTIONS, enc) def clear_actions(self) -> None: - """Clears actions that are already stored on the remote end.""" + """Clears actions that are already stored on the remote end. + + Example: + -------- + >>> action_builder = ActionBuilder(driver) + >>> keyboard = action_builder.key_input + >>> el = driver.find_element(id: "some_id") + >>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys('keys') + >>> action_builder.clear_actions() + """ self.driver.execute(Command.W3C_CLEAR_ACTIONS) def _add_input(self, new_input: Union[KeyInput, PointerInput, WheelInput]) -> None: + """Add a new input device to the action builder. + + Parameters: + ---------- + new_input : Union[KeyInput, PointerInput, WheelInput] + The new input device to add. + """ self.devices.append(new_input) From b277ece15f06190dc2ddac4d467fdd391dfbe2f5 Mon Sep 17 00:00:00 2001 From: Simon Benzer Date: Sun, 12 Jan 2025 13:45:48 -0500 Subject: [PATCH 2/8] format.sh --- py/selenium/webdriver/common/actions/action_builder.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/py/selenium/webdriver/common/actions/action_builder.py b/py/selenium/webdriver/common/actions/action_builder.py index d535a7266658d..d45b7838a2caf 100644 --- a/py/selenium/webdriver/common/actions/action_builder.py +++ b/py/selenium/webdriver/common/actions/action_builder.py @@ -50,12 +50,12 @@ def __init__( def get_device_with(self, name: str) -> Optional[Union["WheelInput", "PointerInput", "KeyInput"]]: """Get the device with the given name. - + Parameters: ---------- name : str The name of the device to get. - + Returns: -------- Optional[Union[WheelInput, PointerInput, KeyInput]] : The device with the given name. @@ -84,7 +84,7 @@ def wheel_action(self) -> WheelActions: def add_key_input(self, name: str) -> KeyInput: """Add a new key input device to the action builder. - + Parameters: ---------- name : str @@ -152,7 +152,7 @@ def add_wheel_input(self, name: str) -> WheelInput: def perform(self) -> None: """Performs all stored actions. - + Example: -------- >>> action_builder = ActionBuilder(driver) @@ -170,7 +170,7 @@ def perform(self) -> None: def clear_actions(self) -> None: """Clears actions that are already stored on the remote end. - + Example: -------- >>> action_builder = ActionBuilder(driver) From edf56f2b9b07b971eda827b85a8da0af8fd7ed1a Mon Sep 17 00:00:00 2001 From: Simon Benzer <69980130+shbenzer@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:47:19 -0500 Subject: [PATCH 3/8] example syntax --- py/selenium/webdriver/common/actions/action_builder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/selenium/webdriver/common/actions/action_builder.py b/py/selenium/webdriver/common/actions/action_builder.py index d45b7838a2caf..ae9d387e4b5de 100644 --- a/py/selenium/webdriver/common/actions/action_builder.py +++ b/py/selenium/webdriver/common/actions/action_builder.py @@ -175,7 +175,7 @@ def clear_actions(self) -> None: -------- >>> action_builder = ActionBuilder(driver) >>> keyboard = action_builder.key_input - >>> el = driver.find_element(id: "some_id") + >>> el = driver.find_element(By.ID, "some_id") >>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys('keys') >>> action_builder.clear_actions() """ From 524b86d8b907c4ad0737d98f5aa935ce4f0caa2b Mon Sep 17 00:00:00 2001 From: Simon Benzer <69980130+shbenzer@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:48:06 -0500 Subject: [PATCH 4/8] example syntax --- py/selenium/webdriver/common/actions/action_builder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/selenium/webdriver/common/actions/action_builder.py b/py/selenium/webdriver/common/actions/action_builder.py index ae9d387e4b5de..7b2ec1adbb680 100644 --- a/py/selenium/webdriver/common/actions/action_builder.py +++ b/py/selenium/webdriver/common/actions/action_builder.py @@ -158,7 +158,7 @@ def perform(self) -> None: >>> action_builder = ActionBuilder(driver) >>> keyboard = action_builder.key_input >>> el = driver.find_element(id: "some_id") - >>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys('keys').perform + >>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys('keys').perform() """ enc = {"actions": []} for device in self.devices: From 226bd8a6e378a64c1985bcef1a6fa86eb49518e6 Mon Sep 17 00:00:00 2001 From: Simon Benzer Date: Sun, 12 Jan 2025 14:57:01 -0500 Subject: [PATCH 5/8] format.sh --- .../common/actions/action_builder.py | 8 ++-- scripts/format.sh | 40 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/py/selenium/webdriver/common/actions/action_builder.py b/py/selenium/webdriver/common/actions/action_builder.py index 7b2ec1adbb680..8b7a90bf4302e 100644 --- a/py/selenium/webdriver/common/actions/action_builder.py +++ b/py/selenium/webdriver/common/actions/action_builder.py @@ -89,11 +89,11 @@ def add_key_input(self, name: str) -> KeyInput: ---------- name : str The name of the key input device. - + Returns: -------- KeyInput : The newly created key input device. - + Example: -------- >>> action_builder = ActionBuilder(driver) @@ -115,7 +115,7 @@ def add_pointer_input(self, kind: str, name: str) -> PointerInput: - "pen" name : str The name of the pointer input device. - + Returns: -------- PointerInput : The newly created pointer input device. @@ -136,7 +136,7 @@ def add_wheel_input(self, name: str) -> WheelInput: ---------- name : str The name of the wheel input device. - + Returns: -------- WheelInput : The newly created wheel input device. diff --git a/scripts/format.sh b/scripts/format.sh index df0156aa14efe..22ef65eed7d2d 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -10,26 +10,26 @@ WORKSPACE_ROOT="$(bazel info workspace 2>/dev/null)" GOOGLE_JAVA_FORMAT="$(bazel run --run_under=echo //scripts:google-java-format)" -section "Buildifier" -echo " buildifier" >&2 -bazel run //:buildifier - -section "Java" -echo " google-java-format" >&2 -find "$PWD/java" -type f -name '*.java' | xargs "$GOOGLE_JAVA_FORMAT" --replace - -section "Javascript" -echo " javascript/node/selenium-webdriver - prettier" >&2 -NODE_WEBDRIVER="${WORKSPACE_ROOT}/javascript/node/selenium-webdriver" -bazel run //javascript:prettier -- "${NODE_WEBDRIVER}" --write "${NODE_WEBDRIVER}/.prettierrc" - -section "Ruby" -echo " rubocop" >&2 -bazel run //rb:lint - -section "Rust" -echo " rustfmt" >&2 -bazel run @rules_rust//:rustfmt +# section "Buildifier" +# echo " buildifier" >&2 +# bazel run //:buildifier + +# section "Java" +# echo " google-java-format" >&2 +# find "$PWD/java" -type f -name '*.java' | xargs "$GOOGLE_JAVA_FORMAT" --replace + +# section "Javascript" +# echo " javascript/node/selenium-webdriver - prettier" >&2 +# NODE_WEBDRIVER="${WORKSPACE_ROOT}/javascript/node/selenium-webdriver" +# bazel run //javascript:prettier -- "${NODE_WEBDRIVER}" --write "${NODE_WEBDRIVER}/.prettierrc" + +# section "Ruby" +# echo " rubocop" >&2 +# bazel run //rb:lint + +# section "Rust" +# echo " rustfmt" >&2 +# bazel run @rules_rust//:rustfmt # TODO: use bazel target when rules_python supports formatting section "Python" From e6c823dba2747c2e3486a8dfd4a395636d29bc3a Mon Sep 17 00:00:00 2001 From: Simon Benzer Date: Sun, 12 Jan 2025 14:57:17 -0500 Subject: [PATCH 6/8] removed comments --- scripts/format.sh | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/format.sh b/scripts/format.sh index 22ef65eed7d2d..df0156aa14efe 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -10,26 +10,26 @@ WORKSPACE_ROOT="$(bazel info workspace 2>/dev/null)" GOOGLE_JAVA_FORMAT="$(bazel run --run_under=echo //scripts:google-java-format)" -# section "Buildifier" -# echo " buildifier" >&2 -# bazel run //:buildifier - -# section "Java" -# echo " google-java-format" >&2 -# find "$PWD/java" -type f -name '*.java' | xargs "$GOOGLE_JAVA_FORMAT" --replace - -# section "Javascript" -# echo " javascript/node/selenium-webdriver - prettier" >&2 -# NODE_WEBDRIVER="${WORKSPACE_ROOT}/javascript/node/selenium-webdriver" -# bazel run //javascript:prettier -- "${NODE_WEBDRIVER}" --write "${NODE_WEBDRIVER}/.prettierrc" - -# section "Ruby" -# echo " rubocop" >&2 -# bazel run //rb:lint - -# section "Rust" -# echo " rustfmt" >&2 -# bazel run @rules_rust//:rustfmt +section "Buildifier" +echo " buildifier" >&2 +bazel run //:buildifier + +section "Java" +echo " google-java-format" >&2 +find "$PWD/java" -type f -name '*.java' | xargs "$GOOGLE_JAVA_FORMAT" --replace + +section "Javascript" +echo " javascript/node/selenium-webdriver - prettier" >&2 +NODE_WEBDRIVER="${WORKSPACE_ROOT}/javascript/node/selenium-webdriver" +bazel run //javascript:prettier -- "${NODE_WEBDRIVER}" --write "${NODE_WEBDRIVER}/.prettierrc" + +section "Ruby" +echo " rubocop" >&2 +bazel run //rb:lint + +section "Rust" +echo " rustfmt" >&2 +bazel run @rules_rust//:rustfmt # TODO: use bazel target when rules_python supports formatting section "Python" From 52c6671d76cd6cdce1dabedb392fff7e112087a5 Mon Sep 17 00:00:00 2001 From: Simon Benzer <69980130+shbenzer@users.noreply.github.com> Date: Mon, 13 Jan 2025 08:53:56 -0500 Subject: [PATCH 7/8] Change Parameters to Attributes --- py/selenium/webdriver/common/actions/action_builder.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/py/selenium/webdriver/common/actions/action_builder.py b/py/selenium/webdriver/common/actions/action_builder.py index 8b7a90bf4302e..22167ee11113f 100644 --- a/py/selenium/webdriver/common/actions/action_builder.py +++ b/py/selenium/webdriver/common/actions/action_builder.py @@ -51,7 +51,7 @@ def __init__( def get_device_with(self, name: str) -> Optional[Union["WheelInput", "PointerInput", "KeyInput"]]: """Get the device with the given name. - Parameters: + Attributes: ---------- name : str The name of the device to get. @@ -85,7 +85,7 @@ def wheel_action(self) -> WheelActions: def add_key_input(self, name: str) -> KeyInput: """Add a new key input device to the action builder. - Parameters: + Attributes: ---------- name : str The name of the key input device. @@ -106,7 +106,7 @@ def add_key_input(self, name: str) -> KeyInput: def add_pointer_input(self, kind: str, name: str) -> PointerInput: """Add a new pointer input device to the action builder. - Parameters: + Attributes: ---------- kind : str The kind of pointer input device. @@ -132,7 +132,7 @@ def add_pointer_input(self, kind: str, name: str) -> PointerInput: def add_wheel_input(self, name: str) -> WheelInput: """Add a new wheel input device to the action builder. - Parameters: + Attributes: ---------- name : str The name of the wheel input device. @@ -184,7 +184,7 @@ def clear_actions(self) -> None: def _add_input(self, new_input: Union[KeyInput, PointerInput, WheelInput]) -> None: """Add a new input device to the action builder. - Parameters: + Attributes: ---------- new_input : Union[KeyInput, PointerInput, WheelInput] The new input device to add. From eb6c38ac550845153d289eef055d8930609db79a Mon Sep 17 00:00:00 2001 From: Simon Benzer <69980130+shbenzer@users.noreply.github.com> Date: Mon, 13 Jan 2025 09:03:03 -0500 Subject: [PATCH 8/8] clarification --- py/selenium/webdriver/common/actions/action_builder.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/py/selenium/webdriver/common/actions/action_builder.py b/py/selenium/webdriver/common/actions/action_builder.py index 22167ee11113f..8b7a90bf4302e 100644 --- a/py/selenium/webdriver/common/actions/action_builder.py +++ b/py/selenium/webdriver/common/actions/action_builder.py @@ -51,7 +51,7 @@ def __init__( def get_device_with(self, name: str) -> Optional[Union["WheelInput", "PointerInput", "KeyInput"]]: """Get the device with the given name. - Attributes: + Parameters: ---------- name : str The name of the device to get. @@ -85,7 +85,7 @@ def wheel_action(self) -> WheelActions: def add_key_input(self, name: str) -> KeyInput: """Add a new key input device to the action builder. - Attributes: + Parameters: ---------- name : str The name of the key input device. @@ -106,7 +106,7 @@ def add_key_input(self, name: str) -> KeyInput: def add_pointer_input(self, kind: str, name: str) -> PointerInput: """Add a new pointer input device to the action builder. - Attributes: + Parameters: ---------- kind : str The kind of pointer input device. @@ -132,7 +132,7 @@ def add_pointer_input(self, kind: str, name: str) -> PointerInput: def add_wheel_input(self, name: str) -> WheelInput: """Add a new wheel input device to the action builder. - Attributes: + Parameters: ---------- name : str The name of the wheel input device. @@ -184,7 +184,7 @@ def clear_actions(self) -> None: def _add_input(self, new_input: Union[KeyInput, PointerInput, WheelInput]) -> None: """Add a new input device to the action builder. - Attributes: + Parameters: ---------- new_input : Union[KeyInput, PointerInput, WheelInput] The new input device to add.