Skip to content
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

Add examples for drivers http_client in java and python #2041

Merged
merged 3 commits into from
Nov 5, 2024

Conversation

VietND96
Copy link
Member

@VietND96 VietND96 commented Nov 5, 2024

User description

Thanks for contributing to the Selenium site and documentation!
A PR well described will help maintainers to review and merge it quickly

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, and help reviewers by making them as simple and short as possible.

Description

Motivation and Context

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • Code example added (and I also added the example to all translated languages)
  • Improved translation
  • Added new translation (and I also added a notice to each document missing translation)

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

PR Type

enhancement, tests


Description

  • Added examples and tests for HTTP client configuration in both Java and Python.
  • Introduced fixtures and methods to start Selenium grid servers with SSL and authentication.
  • Updated documentation to include new Python example references.
  • Added TLS certificate and key files for testing purposes.
  • Updated Python requirements to include the requests library.

Changes walkthrough 📝

Relevant files
Enhancement
2 files
conftest.py
Add Selenium grid server fixture and resource path function

examples/python/tests/conftest.py

  • Added requests and HTTPBasicAuth imports.
  • Introduced _get_resource_path function for file path resolution.
  • Added grid_server fixture to start and manage a Selenium server.
  • +87/-0   
    BaseTest.java
    Enhance BaseTest with advanced grid start method                 

    examples/java/src/test/java/dev/selenium/BaseTest.java

  • Added fields for username, password, and trustStorePassword.
  • Introduced startStandaloneGridAdvanced method with SSL configuration.
  • +36/-0   
    Tests
    2 files
    test_http_client.py
    Add tests for remote WebDriver with client config               

    examples/python/tests/drivers/test_http_client.py

  • Added tests for starting remote WebDriver with client configuration.
  • Utilized grid_server fixture for test setup.
  • Implemented proxy and client configuration in tests.
  • +53/-0   
    HttpClientTest.java
    Add HttpClient tests with SSL and authentication                 

    examples/java/src/test/java/dev/selenium/drivers/HttpClientTest.java

  • Added tests for RemoteWebDriver with client configuration.
  • Implemented SSL context creation methods.
  • Configured tests to authenticate and manage SSL.
  • +105/-0 
    Miscellaneous
    4 files
    tls.crt
    Add TLS certificate for Java tests                                             

    examples/java/src/test/resources/tls.crt

    • Added TLS certificate file for testing.
    +24/-0   
    tls.key
    Add TLS private key for Java tests                                             

    examples/java/src/test/resources/tls.key

    • Added TLS private key file for testing.
    +28/-0   
    tls.crt
    Add TLS certificate for Python tests                                         

    examples/python/tests/resources/tls.crt

    • Added TLS certificate file for Python tests.
    +24/-0   
    tls.key
    Add TLS private key for Python tests                                         

    examples/python/tests/resources/tls.key

    • Added TLS private key file for Python tests.
    +28/-0   
    Dependencies
    1 files
    requirements.txt
    Update Python requirements with requests library                 

    examples/python/requirements.txt

    • Added requests library to requirements.
    +1/-0     
    Documentation
    1 files
    http_client.en.md
    Update Python code block in documentation                               

    website_and_docs/content/documentation/webdriver/drivers/http_client.en.md

    • Updated Python example code block reference.
    +1/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    qodo-merge-pro bot commented Nov 5, 2024

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 PR contains tests
    🔒 Security concerns

    Sensitive information exposure:
    The PR introduces hardcoded credentials and SSL certificates in both Python and Java test files. While these are likely intended for testing purposes, it's important to ensure that such sensitive information is not accidentally committed to version control or deployed to production environments. Consider using environment variables or a secure secret management system to handle these credentials and certificates.

    SSL verification bypass: The Java test file includes a method createIgnoreSSLContext that creates a trust manager accepting all certificates without verification. This practice can lead to security vulnerabilities if used in production code, as it bypasses SSL certificate validation, potentially allowing man-in-the-middle attacks.

    ⚡ Recommended focus areas for review

    Security Concern
    The grid_server fixture uses hardcoded credentials. Consider using environment variables or a secure secret management system for sensitive information.

    Security Concern
    Hardcoded credentials and trust store password are used. Consider using environment variables or a secure secret management system for sensitive information.

    Security Vulnerability
    The createIgnoreSSLContext method creates a trust manager that accepts all certificates without verification. This can lead to security vulnerabilities in production environments.

    Copy link

    netlify bot commented Nov 5, 2024

    Deploy Preview for selenium-dev ready!

    Name Link
    🔨 Latest commit 707454d
    🔍 Latest deploy log https://app.netlify.com/sites/selenium-dev/deploys/6729da046632eb000816ba2f
    😎 Deploy Preview https://deploy-preview-2041--selenium-dev.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    Copy link
    Contributor

    qodo-merge-pro bot commented Nov 5, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Use a context manager for subprocess to ensure proper cleanup

    Use a context manager to ensure proper cleanup of the Selenium server process.

    examples/python/tests/conftest.py [303-325]

    -process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    +with subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as process:
    +    def wait_for_server(url, timeout=60):
    +        start = time.time()
    +        while time.time() - start < timeout:
    +            try:
    +                requests.get(url, verify=_path_cert, auth=HTTPBasicAuth(_username, _password))
    +                return True
    +            except OSError as e:
    +                print(e)
    +                time.sleep(0.2)
    +        return False
     
    -def wait_for_server(url, timeout=60):
    -    start = time.time()
    -    while time.time() - start < timeout:
    -        try:
    -            requests.get(url, verify=_path_cert, auth=HTTPBasicAuth(_username, _password))
    -            return True
    -        except OSError as e:
    -            print(e)
    -            time.sleep(0.2)
    -    return False
    +    if not wait_for_server(f"https://{_host}:{_port}/status"):
    +        raise RuntimeError(f"Selenium server did not start within the allotted time.")
     
    -if not wait_for_server(f"https://{_host}:{_port}/status"):
    -    raise RuntimeError(f"Selenium server did not start within the allotted time.")
    +    yield f"https://{_host}:{_port}"
     
    -yield f"https://{_host}:{_port}"
    +    process.terminate()
    +    try:
    +        process.wait(timeout=10)
    +    except subprocess.TimeoutExpired:
    +        process.kill()
     
    -process.terminate()
    -try:
    -    process.wait(timeout=10)
    -except subprocess.TimeoutExpired:
    -    process.kill()
    -
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using a context manager ensures proper cleanup of resources, even if an exception occurs. This improves code reliability and resource management.

    7
    Use a more specific exception type for better error handling

    Consider using a more specific exception type instead of a broad Exception in the
    except clause.

    examples/python/tests/drivers/test_http_client.py [309-311]

    -except Exception as e:
    +except requests.RequestException as e:
         print(e)
         time.sleep(0.2)
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: Using a more specific exception type (requests.RequestException) improves error handling and makes the code more robust and easier to debug.

    5
    Maintainability
    Extract common configuration setup to reduce code duplication

    Consider extracting the common configuration setup into a separate method to reduce
    code duplication.

    examples/java/src/test/java/dev/selenium/drivers/HttpClientTest.java [40-46]

    -ClientConfig clientConfig = ClientConfig.defaultConfig()
    -        .withRetries()
    -        .sslContext(createSSLContextWithCA(Path.of("src/test/resources/tls.crt").toAbsolutePath().toString()))
    -        .connectionTimeout(Duration.ofSeconds(300))
    -        .readTimeout(Duration.ofSeconds(3600))
    -        .authenticateAs(new UsernameAndPassword("admin", "myStrongPassword"))
    -        .version(HTTP_1_1.toString());
    +private ClientConfig createCommonClientConfig(SSLContext sslContext) {
    +    return ClientConfig.defaultConfig()
    +            .withRetries()
    +            .sslContext(sslContext)
    +            .connectionTimeout(Duration.ofSeconds(300))
    +            .readTimeout(Duration.ofSeconds(3600))
    +            .authenticateAs(new UsernameAndPassword("admin", "myStrongPassword"))
    +            .version(HTTP_1_1.toString());
    +}
     
    +// Usage in tests:
    +ClientConfig clientConfig = createCommonClientConfig(createSSLContextWithCA(Path.of("src/test/resources/tls.crt").toAbsolutePath().toString()));
    +
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Extracting common configuration setup reduces code duplication, improving maintainability and readability of the test class.

    6
    Use a constant for the TLS certificate file path to improve maintainability

    Consider using a constant for the path to the TLS certificate file to improve
    maintainability.

    examples/java/src/test/java/dev/selenium/drivers/HttpClientTest.java [42]

    -Path.of("src/test/resources/tls.crt").toAbsolutePath().toString()
    +private static final String TLS_CERT_PATH = "src/test/resources/tls.crt";
    +// ...
    +Path.of(TLS_CERT_PATH).toAbsolutePath().toString()
    Suggestion importance[1-10]: 4

    Why: Using a constant for the TLS certificate file path improves maintainability by centralizing the path definition, making it easier to update if needed.

    4

    💡 Need additional feedback ? start a PR chat

    Copy link
    Contributor

    qodo-merge-pro bot commented Nov 5, 2024

    CI Failure Feedback 🧐

    (Checks updated until commit 707454d)

    Action: tests (macos, stable)

    Failed stage: Run tests [❌]

    Failed test name: test_mutation

    Failure summary:

    The action failed due to multiple test failures:

  • test_basic_options in tests/browsers/test_safari.py failed because the SafariRemoteConnection
    initialization is missing the required positional argument remote_server_addr.
  • test_enable_logging in tests/browsers/test_safari.py also failed for the same reason as
    test_basic_options.
  • test_mutation in tests/bidi/cdp/test_script.py failed due to an InvalidSelectorException caused by
    an invalid or illegal selector specified in a Selenium WebDriver command.

  • Relevant error logs:
    1:  ##[group]Operating System
    2:  macOS
    ...
    
    152:  Installing collected packages: pip
    153:  Successfully installed pip-24.3.1
    154:  Install OpenSSL certificates
    155:  Collecting certifi
    156:  Using cached certifi-2024.8.30-py3-none-any.whl.metadata (2.2 kB)
    157:  Using cached certifi-2024.8.30-py3-none-any.whl (167 kB)
    158:  Installing collected packages: certifi
    159:  Successfully installed certifi-2024.8.30
    160:  ##[error][notice] A new release of pip is available: 21.1.1 -> 24.3.1
    ...
    
    316:  timeout_minutes: 40
    317:  max_attempts: 3
    318:  command: cd examples/python
    319:  pytest
    320:  
    321:  retry_wait_seconds: 10
    322:  polling_interval_seconds: 1
    323:  warning_on_retry: true
    324:  continue_on_error: false
    ...
    
    361:  tests/elements/test_file_upload.py .                                     [ 77%]
    362:  tests/interactions/test_alerts.py ...                                    [ 79%]
    363:  tests/interactions/test_print_options.py .......                         [ 84%]
    364:  tests/interactions/test_prints_page.py .                                 [ 85%]
    365:  tests/interactions/test_virtual_authenticator.py ..........              [ 93%]
    366:  tests/support/test_select_list.py ...                                    [ 95%]
    367:  tests/troubleshooting/test_logging.py .                                  [ 96%]
    368:  tests/waits/test_waits.py .....                                          [100%]
    369:  =================================== FAILURES ===================================
    ...
    
    421:  |     raise exception.with_traceback(exception.__traceback__)
    422:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pluggy/_callers.py", line 103, in _multicall
    423:  |     res = hook_impl.function(*args)
    424:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/_pytest/python.py", line 159, in pytest_pyfunc_call
    425:  |     result = testfunction(**testargs)
    426:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytest_trio/plugin.py", line 348, in wrapper
    427:  |     return run(partial(fn, **kwargs), clock=clock, instruments=instruments)
    428:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/trio/_core/_run.py", line 2407, in run
    429:  |     raise runner.main_task_outcome.error
    430:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytest_trio/plugin.py", line 426, in _bootstrap_fixtures_and_run_test
    431:  |     raise test_ctx.error_list[0]
    432:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytest_trio/plugin.py", line 197, in _fixture_manager
    433:  |     nursery_fixture.cancel_scope.cancel()
    434:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/trio/_core/_run.py", line 1039, in __aexit__
    435:  |     raise combined_error_from_nursery
    ...
    
    446:  |     await self.gen.athrow(typ, value, traceback)
    447:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 1081, in bidi_connection
    448:  |     yield BidiConnection(session, cdp, devtools)
    449:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/contextlib.py", line 189, in __aexit__
    450:  |     await self.gen.athrow(typ, value, traceback)
    451:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/bidi/cdp.py", line 489, in open_cdp
    452:  |     await conn.aclose()
    453:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/trio/_core/_run.py", line 1039, in __aexit__
    454:  |     raise combined_error_from_nursery
    ...
    
    463:  |     await trio.to_thread.run_sync(lambda: driver.find_element(By.ID, "reveal").click())
    464:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/contextlib.py", line 178, in __aexit__
    465:  |     await self.gen.__anext__()
    466:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/log.py", line 93, in mutation_events
    467:  |     elements: list = self.driver.find_elements(By.CSS_SELECTOR, f"*[data-__webdriver_id={payload['target']}]")
    468:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 788, in find_elements
    469:  |     return self.execute(Command.FIND_ELEMENTS, {"using": by, "value": value})["value"] or []
    470:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 380, in execute
    471:  |     self.error_handler.check_response(response)
    472:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    473:  |     raise exception_class(message, screen, stacktrace)
    474:  | selenium.common.exceptions.InvalidSelectorException: Message: invalid selector
    475:  | from javascript error: {"status":32,"value":"An invalid or illegal selector was specified"}
    476:  |   (Session info: chrome=130.0.6723.59); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#invalid-selector-exception
    ...
    
    499:  +------------------------------------
    500:  ______________________________ test_basic_options ______________________________
    501:  @pytest.mark.skipif(sys.platform != "darwin", reason="requires Mac")
    502:  def test_basic_options():
    503:  options = webdriver.SafariOptions()
    504:  >       driver = webdriver.Safari(options=options)
    505:  tests/browsers/test_safari.py:10: 
    506:  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    507:  self = <[AttributeError("'WebDriver' object has no attribute 'session_id'") raised in repr()] WebDriver object at 0x1074dd4c0>
    ...
    
    527:  self.service.path = self.service.env_path() or DriverFinder(self.service, options).get_driver_path()
    528:  if not self.service.reuse_service:
    529:  self.service.start()
    530:  client_config = ClientConfig(remote_server_addr=self.service.service_url, keep_alive=keep_alive, timeout=120)
    531:  >       executor = SafariRemoteConnection(
    532:  ignore_proxy=options._ignore_local_proxy,
    533:  client_config=client_config,
    534:  )
    535:  E       TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    536:  /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/safari/webdriver.py:55: TypeError
    537:  _____________________________ test_enable_logging ______________________________
    538:  @pytest.mark.skipif(sys.platform != "darwin", reason="requires Mac")
    539:  def test_enable_logging():
    540:  service = webdriver.SafariService(service_args=["--diagnose"])
    541:  >       driver = webdriver.Safari(service=service)
    542:  tests/browsers/test_safari.py:19: 
    543:  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    544:  self = <[AttributeError("'WebDriver' object has no attribute 'session_id'") raised in repr()] WebDriver object at 0x107502b50>
    ...
    
    564:  self.service.path = self.service.env_path() or DriverFinder(self.service, options).get_driver_path()
    565:  if not self.service.reuse_service:
    566:  self.service.start()
    567:  client_config = ClientConfig(remote_server_addr=self.service.service_url, keep_alive=keep_alive, timeout=120)
    568:  >       executor = SafariRemoteConnection(
    569:  ignore_proxy=options._ignore_local_proxy,
    570:  client_config=client_config,
    571:  )
    572:  E       TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    573:  /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/safari/webdriver.py:55: TypeError
    ...
    
    587:  tests/drivers/test_http_client.py:12
    588:  /Users/runner/work/seleniumhq.github.io/seleniumhq.github.io/examples/python/tests/drivers/test_http_client.py:12: PytestUnknownMarkWarning: Unknown pytest.mark.sanity - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    589:  @pytest.mark.sanity
    590:  tests/drivers/test_http_client.py:29
    591:  /Users/runner/work/seleniumhq.github.io/seleniumhq.github.io/examples/python/tests/drivers/test_http_client.py:29: PytestUnknownMarkWarning: Unknown pytest.mark.sanity - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    592:  @pytest.mark.sanity
    593:  -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
    594:  =========================== short test summary info ============================
    595:  FAILED tests/bidi/cdp/test_script.py::test_mutation - exceptiongroup.ExceptionGroup: Exceptions from Trio nursery (1 sub-exception)
    596:  FAILED tests/browsers/test_safari.py::test_basic_options - TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    597:  FAILED tests/browsers/test_safari.py::test_enable_logging - TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    598:  ======= 3 failed, 123 passed, 7 skipped, 6 warnings in 282.76s (0:04:42) =======
    599:  ##[warning]Attempt 1 failed. Reason: Child_process exited with error code 1
    ...
    
    624:  tests/elements/test_file_upload.py .                                     [ 77%]
    625:  tests/interactions/test_alerts.py ...                                    [ 79%]
    626:  tests/interactions/test_print_options.py .......                         [ 84%]
    627:  tests/interactions/test_prints_page.py .                                 [ 85%]
    628:  tests/interactions/test_virtual_authenticator.py ..........              [ 93%]
    629:  tests/support/test_select_list.py ...                                    [ 95%]
    630:  tests/troubleshooting/test_logging.py .                                  [ 96%]
    631:  tests/waits/test_waits.py .....                                          [100%]
    632:  =================================== FAILURES ===================================
    633:  ______________________________ test_basic_options ______________________________
    634:  @pytest.mark.skipif(sys.platform != "darwin", reason="requires Mac")
    635:  def test_basic_options():
    636:  options = webdriver.SafariOptions()
    637:  >       driver = webdriver.Safari(options=options)
    638:  tests/browsers/test_safari.py:10: 
    639:  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    640:  self = <[AttributeError("'WebDriver' object has no attribute 'session_id'") raised in repr()] WebDriver object at 0x106df8400>
    ...
    
    660:  self.service.path = self.service.env_path() or DriverFinder(self.service, options).get_driver_path()
    661:  if not self.service.reuse_service:
    662:  self.service.start()
    663:  client_config = ClientConfig(remote_server_addr=self.service.service_url, keep_alive=keep_alive, timeout=120)
    664:  >       executor = SafariRemoteConnection(
    665:  ignore_proxy=options._ignore_local_proxy,
    666:  client_config=client_config,
    667:  )
    668:  E       TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    669:  /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/safari/webdriver.py:55: TypeError
    670:  _____________________________ test_enable_logging ______________________________
    671:  @pytest.mark.skipif(sys.platform != "darwin", reason="requires Mac")
    672:  def test_enable_logging():
    673:  service = webdriver.SafariService(service_args=["--diagnose"])
    674:  >       driver = webdriver.Safari(service=service)
    675:  tests/browsers/test_safari.py:19: 
    676:  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    677:  self = <[AttributeError("'WebDriver' object has no attribute 'session_id'") raised in repr()] WebDriver object at 0x106dd81c0>
    ...
    
    697:  self.service.path = self.service.env_path() or DriverFinder(self.service, options).get_driver_path()
    698:  if not self.service.reuse_service:
    699:  self.service.start()
    700:  client_config = ClientConfig(remote_server_addr=self.service.service_url, keep_alive=keep_alive, timeout=120)
    701:  >       executor = SafariRemoteConnection(
    702:  ignore_proxy=options._ignore_local_proxy,
    703:  client_config=client_config,
    704:  )
    705:  E       TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    706:  /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/safari/webdriver.py:55: TypeError
    ...
    
    720:  tests/drivers/test_http_client.py:12
    721:  /Users/runner/work/seleniumhq.github.io/seleniumhq.github.io/examples/python/tests/drivers/test_http_client.py:12: PytestUnknownMarkWarning: Unknown pytest.mark.sanity - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    722:  @pytest.mark.sanity
    723:  tests/drivers/test_http_client.py:29
    724:  /Users/runner/work/seleniumhq.github.io/seleniumhq.github.io/examples/python/tests/drivers/test_http_client.py:29: PytestUnknownMarkWarning: Unknown pytest.mark.sanity - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    725:  @pytest.mark.sanity
    726:  -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
    727:  =========================== short test summary info ============================
    728:  FAILED tests/browsers/test_safari.py::test_basic_options - TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    729:  FAILED tests/browsers/test_safari.py::test_enable_logging - TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    730:  ======= 2 failed, 124 passed, 7 skipped, 6 warnings in 319.12s (0:05:19) =======
    731:  ##[warning]Attempt 2 failed. Reason: Child_process exited with error code 1
    ...
    
    756:  tests/elements/test_file_upload.py .                                     [ 77%]
    757:  tests/interactions/test_alerts.py ...                                    [ 79%]
    758:  tests/interactions/test_print_options.py .......                         [ 84%]
    759:  tests/interactions/test_prints_page.py .                                 [ 85%]
    760:  tests/interactions/test_virtual_authenticator.py ..........              [ 93%]
    761:  tests/support/test_select_list.py ...                                    [ 95%]
    762:  tests/troubleshooting/test_logging.py .                                  [ 96%]
    763:  tests/waits/test_waits.py .....                                          [100%]
    764:  =================================== FAILURES ===================================
    ...
    
    816:  |     raise exception.with_traceback(exception.__traceback__)
    817:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pluggy/_callers.py", line 103, in _multicall
    818:  |     res = hook_impl.function(*args)
    819:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/_pytest/python.py", line 159, in pytest_pyfunc_call
    820:  |     result = testfunction(**testargs)
    821:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytest_trio/plugin.py", line 348, in wrapper
    822:  |     return run(partial(fn, **kwargs), clock=clock, instruments=instruments)
    823:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/trio/_core/_run.py", line 2407, in run
    824:  |     raise runner.main_task_outcome.error
    825:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytest_trio/plugin.py", line 426, in _bootstrap_fixtures_and_run_test
    826:  |     raise test_ctx.error_list[0]
    827:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytest_trio/plugin.py", line 197, in _fixture_manager
    828:  |     nursery_fixture.cancel_scope.cancel()
    829:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/trio/_core/_run.py", line 1039, in __aexit__
    830:  |     raise combined_error_from_nursery
    ...
    
    841:  |     await self.gen.athrow(typ, value, traceback)
    842:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 1081, in bidi_connection
    843:  |     yield BidiConnection(session, cdp, devtools)
    844:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/contextlib.py", line 189, in __aexit__
    845:  |     await self.gen.athrow(typ, value, traceback)
    846:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/bidi/cdp.py", line 489, in open_cdp
    847:  |     await conn.aclose()
    848:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/trio/_core/_run.py", line 1039, in __aexit__
    849:  |     raise combined_error_from_nursery
    ...
    
    858:  |     await trio.to_thread.run_sync(lambda: driver.find_element(By.ID, "reveal").click())
    859:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/contextlib.py", line 178, in __aexit__
    860:  |     await self.gen.__anext__()
    861:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/log.py", line 93, in mutation_events
    862:  |     elements: list = self.driver.find_elements(By.CSS_SELECTOR, f"*[data-__webdriver_id={payload['target']}]")
    863:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 788, in find_elements
    864:  |     return self.execute(Command.FIND_ELEMENTS, {"using": by, "value": value})["value"] or []
    865:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 380, in execute
    866:  |     self.error_handler.check_response(response)
    867:  |   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    868:  |     raise exception_class(message, screen, stacktrace)
    869:  | selenium.common.exceptions.InvalidSelectorException: Message: invalid selector
    870:  | from javascript error: {"status":32,"value":"An invalid or illegal selector was specified"}
    871:  |   (Session info: chrome=130.0.6723.59); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#invalid-selector-exception
    ...
    
    894:  +------------------------------------
    895:  ______________________________ test_basic_options ______________________________
    896:  @pytest.mark.skipif(sys.platform != "darwin", reason="requires Mac")
    897:  def test_basic_options():
    898:  options = webdriver.SafariOptions()
    899:  >       driver = webdriver.Safari(options=options)
    900:  tests/browsers/test_safari.py:10: 
    901:  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    902:  self = <[AttributeError("'WebDriver' object has no attribute 'session_id'") raised in repr()] WebDriver object at 0x10700b880>
    ...
    
    922:  self.service.path = self.service.env_path() or DriverFinder(self.service, options).get_driver_path()
    923:  if not self.service.reuse_service:
    924:  self.service.start()
    925:  client_config = ClientConfig(remote_server_addr=self.service.service_url, keep_alive=keep_alive, timeout=120)
    926:  >       executor = SafariRemoteConnection(
    927:  ignore_proxy=options._ignore_local_proxy,
    928:  client_config=client_config,
    929:  )
    930:  E       TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    931:  /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/safari/webdriver.py:55: TypeError
    932:  _____________________________ test_enable_logging ______________________________
    933:  @pytest.mark.skipif(sys.platform != "darwin", reason="requires Mac")
    934:  def test_enable_logging():
    935:  service = webdriver.SafariService(service_args=["--diagnose"])
    936:  >       driver = webdriver.Safari(service=service)
    937:  tests/browsers/test_safari.py:19: 
    938:  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    939:  self = <[AttributeError("'WebDriver' object has no attribute 'session_id'") raised in repr()] WebDriver object at 0x1061031f0>
    ...
    
    959:  self.service.path = self.service.env_path() or DriverFinder(self.service, options).get_driver_path()
    960:  if not self.service.reuse_service:
    961:  self.service.start()
    962:  client_config = ClientConfig(remote_server_addr=self.service.service_url, keep_alive=keep_alive, timeout=120)
    963:  >       executor = SafariRemoteConnection(
    964:  ignore_proxy=options._ignore_local_proxy,
    965:  client_config=client_config,
    966:  )
    967:  E       TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    968:  /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/safari/webdriver.py:55: TypeError
    ...
    
    982:  tests/drivers/test_http_client.py:12
    983:  /Users/runner/work/seleniumhq.github.io/seleniumhq.github.io/examples/python/tests/drivers/test_http_client.py:12: PytestUnknownMarkWarning: Unknown pytest.mark.sanity - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    984:  @pytest.mark.sanity
    985:  tests/drivers/test_http_client.py:29
    986:  /Users/runner/work/seleniumhq.github.io/seleniumhq.github.io/examples/python/tests/drivers/test_http_client.py:29: PytestUnknownMarkWarning: Unknown pytest.mark.sanity - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    987:  @pytest.mark.sanity
    988:  -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
    989:  =========================== short test summary info ============================
    990:  FAILED tests/bidi/cdp/test_script.py::test_mutation - exceptiongroup.ExceptionGroup: Exceptions from Trio nursery (1 sub-exception)
    991:  FAILED tests/browsers/test_safari.py::test_basic_options - TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    992:  FAILED tests/browsers/test_safari.py::test_enable_logging - TypeError: __init__() missing 1 required positional argument: 'remote_server_addr'
    993:  ======= 3 failed, 123 passed, 7 skipped, 6 warnings in 312.90s (0:05:12) =======
    994:  ##[error]Final attempt failed. Child_process exited with error code 1
    

    ✨ CI feedback usage guide:

    The CI feedback tool (/checks) automatically triggers when a PR has a failed check.
    The tool analyzes the failed checks and provides several feedbacks:

    • Failed stage
    • Failed test name
    • Failure summary
    • Relevant error logs

    In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR:

    /checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}"
    

    where {repo_name} is the name of the repository, {run_number} is the run number of the failed check, and {job_number} is the job number of the failed check.

    Configuration options

    • enable_auto_checks_feedback - if set to true, the tool will automatically provide feedback when a check is failed. Default is true.
    • excluded_checks_list - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list.
    • enable_help_text - if set to true, the tool will provide a help message with the feedback. Default is true.
    • persistent_comment - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true.
    • final_update_message - if persistent_comment is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true.

    See more information about the checks tool in the docs.

    @VietND96 VietND96 force-pushed the example-http-client branch 6 times, most recently from b52ac53 to ea3d5f0 Compare November 5, 2024 03:17
    @VietND96 VietND96 force-pushed the example-http-client branch from ea3d5f0 to 37d1818 Compare November 5, 2024 05:23
    @VietND96 VietND96 force-pushed the example-http-client branch from a5d1955 to 707454d Compare November 5, 2024 08:40
    @VietND96 VietND96 merged commit 2ce6752 into trunk Nov 5, 2024
    17 of 18 checks passed
    @VietND96 VietND96 deleted the example-http-client branch November 5, 2024 09:05
    selenium-ci added a commit that referenced this pull request Nov 5, 2024
    * Add examples for http_client java and python
    * Updated for other languages
    * Fix flaky test in examples python (#2042)
    
    [deploy site]
    
    ---------
    
    Signed-off-by: Viet Nguyen Duc <[email protected]> 2ce6752
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant