-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[🚀 Feature] [py]: Better compatibility with Appium-python #14587
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
27e8a9d
[py] override default locator converter for python
navin772 1278353
Merge branch 'SeleniumHQ:trunk' into override-default-converter-py
navin772 092be17
Support registering custom finders in py
navin772 8a983a1
Support registering extra HTTP commands and methods in python
navin772 81cca0f
Support overriding User-Agent in python
navin772 f27d46c
Support registering extra headers
navin772 26d737d
Merge branch 'SeleniumHQ:trunk' into override-default-converter-py
navin772 845fa18
[py] Support ignore certificates
navin772 4503b1e
Support using custom element classes
navin772 11c4a2c
tests for custom element test
navin772 55ed141
address review comments
navin772 e1e7392
Merge branch 'trunk' into appium-python
harsha509 906f44b
close parenthesis
navin772 9272a49
pass `init_args_for_pool_manager` in constructor
navin772 1087483
Merge branch 'trunk' into appium-python
harsha509 6dd16a2
use existing driver fixture in tests
navin772 21bc74c
convert `add_command` to instance method
navin772 dfd4b7b
Merge branch 'trunk' into appium-python
navin772 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
|
|
||
| class LocatorConverter: | ||
| def convert(self, by, value): | ||
| # Default conversion logic | ||
| if by == "id": | ||
| return "css selector", f'[id="{value}"]' | ||
| elif by == "class name": | ||
| return "css selector", f".{value}" | ||
| elif by == "name": | ||
| return "css selector", f'[name="{value}"]' | ||
| return by, value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| from selenium.webdriver.common.by import By | ||
| from selenium.webdriver.remote.webelement import WebElement | ||
|
|
||
|
|
||
| # Custom element class | ||
| class MyCustomElement(WebElement): | ||
| def custom_method(self): | ||
| return "Custom element method" | ||
|
|
||
|
|
||
| def test_find_element_with_custom_class(driver, pages): | ||
| """Test to ensure custom element class is used for a single element.""" | ||
| driver._web_element_cls = MyCustomElement | ||
| pages.load("simpleTest.html") | ||
| element = driver.find_element(By.TAG_NAME, "body") | ||
| assert isinstance(element, MyCustomElement) | ||
| assert element.custom_method() == "Custom element method" | ||
|
|
||
|
|
||
| def test_find_elements_with_custom_class(driver, pages): | ||
| """Test to ensure custom element class is used for multiple elements.""" | ||
| driver._web_element_cls = MyCustomElement | ||
| pages.load("simpleTest.html") | ||
| elements = driver.find_elements(By.TAG_NAME, "div") | ||
| assert all(isinstance(el, MyCustomElement) for el in elements) | ||
| assert all(el.custom_method() == "Custom element method" for el in elements) | ||
|
|
||
|
|
||
| def test_default_element_class(driver, pages): | ||
| """Test to ensure default WebElement class is used.""" | ||
| pages.load("simpleTest.html") | ||
| element = driver.find_element(By.TAG_NAME, "body") | ||
| assert isinstance(element, WebElement) | ||
| assert not hasattr(element, "custom_method") |
40 changes: 40 additions & 0 deletions
40
py/test/selenium/webdriver/remote/remote_custom_locator_tests.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| from selenium.webdriver.remote.locator_converter import LocatorConverter | ||
|
|
||
|
|
||
| class CustomLocatorConverter(LocatorConverter): | ||
| def convert(self, by, value): | ||
| # Custom conversion logic | ||
| if by == "custom": | ||
| return "css selector", f'[custom-attr="{value}"]' | ||
| return super().convert(by, value) | ||
|
|
||
|
|
||
| def test_find_element_with_custom_locator(driver): | ||
| driver.get("data:text/html,<div custom-attr='example'>Test</div>") | ||
| element = driver.find_element("custom", "example") | ||
| assert element is not None | ||
| assert element.text == "Test" | ||
|
|
||
|
|
||
| def test_find_elements_with_custom_locator(driver): | ||
| driver.get("data:text/html,<div custom-attr='example'>Test1</div><div custom-attr='example'>Test2</div>") | ||
| elements = driver.find_elements("custom", "example") | ||
| assert len(elements) == 2 | ||
| assert elements[0].text == "Test1" | ||
| assert elements[1].text == "Test2" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.