From c52437b2452147b114fd10092c86fe520faf87bd Mon Sep 17 00:00:00 2001 From: Ed Manlove Date: Wed, 4 Sep 2024 22:12:43 -0400 Subject: [PATCH 1/6] Initial Python 3.12 support --- .github/workflows/CI.yml | 2 +- README.rst | 2 +- ..._options_string_errors_py3_12.approved.txt | 8 ++++++++ ..._service_string_errors_py3_12.approved.txt | 8 ++++++++ .../keywords/test_selenium_options_parser.py | 19 ++++++++++++++++--- .../keywords/test_selenium_service_parser.py | 19 ++++++++++++++++++- 6 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 utest/test/keywords/approved_files/test_selenium_options_parser.test_parse_options_string_errors_py3_12.approved.txt create mode 100644 utest/test/keywords/approved_files/test_selenium_service_parser.test_parse_service_string_errors_py3_12.approved.txt diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8db0eff25..c5d2008d8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -9,7 +9,7 @@ jobs: continue-on-error: true strategy: matrix: - python-version: [3.8, 3.11] # 3.12, pypy-3.9 + python-version: [3.8, 3.12] # 3.12, pypy-3.9 rf-version: [5.0.1, 6.1.1, 7.0] selenium-version: [4.20.0, 4.21.0] browser: [firefox, chrome, headlesschrome] #edge diff --git a/README.rst b/README.rst index 85819fcab..727c8e705 100644 --- a/README.rst +++ b/README.rst @@ -10,7 +10,7 @@ SeleniumLibrary_ is a web testing library for `Robot Framework`_ that utilizes the Selenium_ tool internally. The project is hosted on GitHub_ and downloads can be found from PyPI_. -SeleniumLibrary currently works with Selenium 4. It supports Python 3.8 through 3.11. +SeleniumLibrary currently works with Selenium 4. It supports Python 3.8 through 3.12. In addition to the normal Python_ interpreter, it works also with PyPy_. diff --git a/utest/test/keywords/approved_files/test_selenium_options_parser.test_parse_options_string_errors_py3_12.approved.txt b/utest/test/keywords/approved_files/test_selenium_options_parser.test_parse_options_string_errors_py3_12.approved.txt new file mode 100644 index 000000000..d57473c22 --- /dev/null +++ b/utest/test/keywords/approved_files/test_selenium_options_parser.test_parse_options_string_errors_py3_12.approved.txt @@ -0,0 +1,8 @@ +Selenium options string errors + +0) method("arg1) ('unterminated string literal (detected at line 1)', (1, 8)) +1) method(arg1") ('unterminated string literal (detected at line 1)', (1, 12)) +2) method(arg1) Unable to parse option: "method(arg1)" +3) attribute=arg1 Unable to parse option: "attribute=arg1" +4) attribute=webdriver Unable to parse option: "attribute=webdriver" +5) method(argument="value") Unable to parse option: "method(argument="value")" diff --git a/utest/test/keywords/approved_files/test_selenium_service_parser.test_parse_service_string_errors_py3_12.approved.txt b/utest/test/keywords/approved_files/test_selenium_service_parser.test_parse_service_string_errors_py3_12.approved.txt new file mode 100644 index 000000000..44dc032d0 --- /dev/null +++ b/utest/test/keywords/approved_files/test_selenium_service_parser.test_parse_service_string_errors_py3_12.approved.txt @@ -0,0 +1,8 @@ +Selenium service string errors + +0) attribute=arg1 Unable to parse service: "attribute=arg1" +1) attribute='arg1 ('unterminated string literal (detected at line 1)', (1, 11)) +2) attribute=['arg1' ('unexpected EOF in multi-line statement', (1, 0)) +3) attribute=['arg1';'arg2'] ('unexpected EOF in multi-line statement', (1, 0)) +4) attribute['arg1'] Unable to parse service: "attribute['arg1']" +5) attribute=['arg1'] attribute=['arg2'] Unable to parse service: "attribute=['arg1'] attribute=['arg2']" diff --git a/utest/test/keywords/test_selenium_options_parser.py b/utest/test/keywords/test_selenium_options_parser.py index 40e51bdd9..b61fff029 100644 --- a/utest/test/keywords/test_selenium_options_parser.py +++ b/utest/test/keywords/test_selenium_options_parser.py @@ -1,4 +1,5 @@ import os +import sys import unittest import pytest @@ -102,7 +103,8 @@ def test_parse_arguemnts(options, reporter): verify_all("Parse arguments from complex object", results, reporter=reporter) -@unittest.skipIf(WINDOWS, reason="ApprovalTest do not support different line feeds") +@pytest.mark.skipif(WINDOWS, reason="ApprovalTest do not support different line feeds") +@pytest.mark.skipif(sys.version_info > (3, 11), reason="Errors change with Python 3.12") def test_parse_options_string_errors(options, reporter): results = [] results.append(error_formatter(options._parse, 'method("arg1)', True)) @@ -114,6 +116,19 @@ def test_parse_options_string_errors(options, reporter): verify_all("Selenium options string errors", results, reporter=reporter) +@pytest.mark.skipif(WINDOWS, reason="ApprovalTest do not support different line feeds") +@pytest.mark.skipif(sys.version_info < (3, 12), reason="Errors change with Python 3.12") +def test_parse_options_string_errors_py3_12(options, reporter): + results = [] + results.append(error_formatter(options._parse, 'method("arg1)', True)) + results.append(error_formatter(options._parse, 'method(arg1")', True)) + results.append(error_formatter(options._parse, "method(arg1)", True)) + results.append(error_formatter(options._parse, "attribute=arg1", True)) + results.append(error_formatter(options._parse, "attribute=webdriver", True)) + results.append(error_formatter(options._parse, 'method(argument="value")', True)) + verify_all("Selenium options string errors", results, reporter=reporter) + + @unittest.skipIf(WINDOWS, reason="ApprovalTest do not support different line feeds") def test_split_options(options, reporter): results = [] @@ -203,8 +218,6 @@ def output_dir(): output_dir = os.path.abspath(os.path.join(curr_dir, "..", "..", "output_dir")) return output_dir -from selenium.webdriver.chrome.service import Service as ChromeService - def test_create_chrome_with_options(creator): options = mock() diff --git a/utest/test/keywords/test_selenium_service_parser.py b/utest/test/keywords/test_selenium_service_parser.py index 637a208c6..095a8c2c2 100644 --- a/utest/test/keywords/test_selenium_service_parser.py +++ b/utest/test/keywords/test_selenium_service_parser.py @@ -1,4 +1,5 @@ import os +import sys import unittest import pytest @@ -53,7 +54,10 @@ def test_parse_service_string(service, reporter): verify_all("Selenium service string to dict", results, reporter=reporter) -@unittest.skipIf(WINDOWS, reason="ApprovalTest do not support different line feeds") +# @unittest.skipIf(WINDOWS, reason="ApprovalTest do not support different line feeds") +# @unittest.skipIf(sys.version_info > (3, 11), reason="Errors change with Python 3.12") +@pytest.mark.skipif(WINDOWS, reason="ApprovalTest do not support different line feeds") +@pytest.mark.skipif(sys.version_info > (3, 11), reason="Errors change with Python 3.12") def test_parse_service_string_errors(service, reporter): results = [] results.append(error_formatter(service._parse, "attribute=arg1", True)) @@ -65,6 +69,19 @@ def test_parse_service_string_errors(service, reporter): verify_all("Selenium service string errors", results, reporter=reporter) +@pytest.mark.skipif(WINDOWS, reason="ApprovalTest do not support different line feeds") +@pytest.mark.skipif(sys.version_info < (3, 12), reason="Errors change with Python 3.12") +def test_parse_service_string_errors_py3_12(service, reporter): + results = [] + results.append(error_formatter(service._parse, "attribute=arg1", True)) + results.append(error_formatter(service._parse, "attribute='arg1", True)) + results.append(error_formatter(service._parse, "attribute=['arg1'", True)) + results.append(error_formatter(service._parse, "attribute=['arg1';'arg2']", True)) + results.append(error_formatter(service._parse, "attribute['arg1']", True)) + results.append(error_formatter(service._parse, "attribute=['arg1'] attribute=['arg2']", True)) + verify_all("Selenium service string errors", results, reporter=reporter) + + @unittest.skipIf(WINDOWS, reason="ApprovalTest do not support different line feeds") def test_split_service(service, reporter): results = [] From f263368af53eb8a7ded2b5754ab8fbbe18aa2064 Mon Sep 17 00:00:00 2001 From: Ed Manlove Date: Thu, 5 Sep 2024 08:56:45 -0400 Subject: [PATCH 2/6] Triage atest "Should Detect Page Loads While Waiting On An Async Script And Return An Error" is showing some differences I believe with the current Chrome browser version 128. Going to temporarily triage it and see if there are other issues within the test matrix. --- atest/acceptance/keywords/async_javascript.robot | 1 + 1 file changed, 1 insertion(+) diff --git a/atest/acceptance/keywords/async_javascript.robot b/atest/acceptance/keywords/async_javascript.robot index 7fc72b198..646e3dd16 100644 --- a/atest/acceptance/keywords/async_javascript.robot +++ b/atest/acceptance/keywords/async_javascript.robot @@ -88,6 +88,7 @@ Should Timeout If Script Does Not Invoke Callback With Long Timeout ... var callback = arguments[arguments.length - 1]; window.setTimeout(callback, 1500); Should Detect Page Loads While Waiting On An Async Script And Return An Error + [Tags] Triage Set Selenium Timeout 0.5 seconds ${status} ${error} Run Keyword And Ignore Error Execute Async Javascript ... window.location = 'javascript/dynamic'; From f3f41110389c34543fcf0dfbd492f632243ea10b Mon Sep 17 00:00:00 2001 From: Ed Manlove Date: Thu, 5 Sep 2024 13:30:51 -0400 Subject: [PATCH 3/6] Updated tested against Robot Framework versions Removed 5.0.1 as it is not compatable with Python3.12 (which came in RF version 6.1). Also bumped 7.0 to 7.0.1. --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c5d2008d8..4628a13a9 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: python-version: [3.8, 3.12] # 3.12, pypy-3.9 - rf-version: [5.0.1, 6.1.1, 7.0] + rf-version: [6.1.1, 7.0.1] selenium-version: [4.20.0, 4.21.0] browser: [firefox, chrome, headlesschrome] #edge From ff8cfb6ac7742ff11dbf5183c460e94ea2f9c659 Mon Sep 17 00:00:00 2001 From: Ed Manlove Date: Thu, 5 Sep 2024 13:55:50 -0400 Subject: [PATCH 4/6] Updated setup.py with 3.12 support - also cleaned up the github runner --- .github/workflows/CI.yml | 2 +- setup.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 4628a13a9..d61836c57 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -9,7 +9,7 @@ jobs: continue-on-error: true strategy: matrix: - python-version: [3.8, 3.12] # 3.12, pypy-3.9 + python-version: [3.8, 3.12] # pypy-3.9 rf-version: [6.1.1, 7.0.1] selenium-version: [4.20.0, 4.21.0] browser: [firefox, chrome, headlesschrome] #edge diff --git a/setup.py b/setup.py index 8ddead98f..89d86d307 100755 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 +Programming Language :: Python :: 3.12 Programming Language :: Python :: 3 :: Only Topic :: Software Development :: Testing Framework :: Robot Framework @@ -41,7 +42,7 @@ keywords = 'robotframework testing testautomation selenium webdriver web', platforms = 'any', classifiers = CLASSIFIERS, - python_requires = '>=3.8, <3.12', + python_requires = '>=3.8, <=3.12', install_requires = REQUIREMENTS, package_dir = {'': 'src'}, packages = find_packages('src'), From 305b8f6e8654543ca019e8e54b2b77e4965f2ad9 Mon Sep 17 00:00:00 2001 From: Ed Manlove Date: Thu, 5 Sep 2024 14:05:29 -0400 Subject: [PATCH 5/6] Updated Selenium Python versions to latest As I did not keep up with the selenium version over the summer going to test from 4.21.0 to latest (4.24.0) --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d61836c57..2d0bda6c9 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -11,7 +11,7 @@ jobs: matrix: python-version: [3.8, 3.12] # pypy-3.9 rf-version: [6.1.1, 7.0.1] - selenium-version: [4.20.0, 4.21.0] + selenium-version: [4.21.0, 4.22.0, 4.23.1, 4.24.0] browser: [firefox, chrome, headlesschrome] #edge steps: From 948332aa52ffd29ecb9fd55ff2e6420f92654014 Mon Sep 17 00:00:00 2001 From: Ed Manlove Date: Thu, 5 Sep 2024 14:51:39 -0400 Subject: [PATCH 6/6] Updated the "Install drivers via selenium-manager" CI step As we now are only testing Selenium version 2.21 or greater I removed the check to see the correct method name for getting the binaries with Selenium Manage. --- .github/workflows/CI.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2d0bda6c9..d24a0ba01 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -60,11 +60,7 @@ jobs: pip install -U --pre robotframework==${{ matrix.rf-version }} - name: Install drivers via selenium-manager run: | - if [[ ${{ matrix.selenium-version }} == '4.20.0' || ${{ matrix.selenium-version }} == '4.21.0' ]]; then - SELENIUM_MANAGER_EXE=$(python -c 'from selenium.webdriver.common.selenium_manager import SeleniumManager; sm=SeleniumManager(); print(f"{str(sm._get_binary())}")') - else - SELENIUM_MANAGER_EXE=$(python -c 'from selenium.webdriver.common.selenium_manager import SeleniumManager; sm=SeleniumManager(); print(f"{str(sm.get_binary())}")') - fi + SELENIUM_MANAGER_EXE=$(python -c 'from selenium.webdriver.common.selenium_manager import SeleniumManager; sm=SeleniumManager(); print(f"{str(sm._get_binary())}")') echo "$SELENIUM_MANAGER_EXE" echo "WEBDRIVERPATH=$($SELENIUM_MANAGER_EXE --browser chrome --debug | awk '/INFO[[:space:]]Driver path:/ {print $NF;exit}')" >> "$GITHUB_ENV" echo "$WEBDRIVERPATH"