Skip to content

Py safari options#10385

Merged
AutomatedTester merged 4 commits intoSeleniumHQ:trunkfrom
MWschutte:py-safari-options
Mar 1, 2022
Merged

Py safari options#10385
AutomatedTester merged 4 commits intoSeleniumHQ:trunkfrom
MWschutte:py-safari-options

Conversation

@MWschutte
Copy link
Copy Markdown
Contributor

@MWschutte MWschutte commented Feb 21, 2022

Description

Adds same functionality as the the safari options in the java repository. Enables the user to set safari options:

  • Set Safari browser name to technology preview
  • Set Automatic Inspection
  • Set Automatic Profiling

Motivation and Context

Python is the only language not to have a Safari Options class.
Closes #10267

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [ x] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • [x ] I have read the contributing document.
  • [x ] My change requires a change to the documentation.
  • [ x] I have updated the documentation accordingly.
  • [ x] I have added tests to cover my changes.
  • [ x] All new and existing tests passed.

Include the Automatic Profiling and Automatic Inspection option to safarie options. Also add's the options to set browser name to Safari Technology Preview
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 21, 2022

CLA assistant check
All committers have signed the CLA.

@AutomatedTester
Copy link
Copy Markdown
Member

Thanks for the PR. I have started the github actions and there are some failures (tox mostly). Can you have a look at those please

There where some blank lines containing whitespaces which is against the flake8 style convention.
@MWschutte
Copy link
Copy Markdown
Contributor Author

Thanks for the PR. I have started the github actions and there are some failures (tox mostly). Can you have a look at those please

@AutomatedTester thanks for your response. I have fixed the tox failures. I also tried to take a look at why the firefox_tests_remote failed. The bidi_tests.py seems to cause a Timeout. However this PR does not involve changes for the firefox code and all the test in the bidi_test.py are marked with xfail_safari. Furthermore I've noticed this test causing a timeout at other workflows as well.

@AutomatedTester AutomatedTester merged commit 203dadb into SeleniumHQ:trunk Mar 1, 2022
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 1, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@Alraku
Copy link
Copy Markdown

Alraku commented May 21, 2022

Hi, does this feature helps with warning that comes up on MacOS while using safari?
The warning says "DeprecationWarning: desired_capabilities has been deprecated, please pass in an Options object with options kwarg RemoteWebDriver.init("

well now when safari options have been added, how do I get rid of this warning? How do I pass properly the arguments while initialising web driver for safari?

@titusfortner
Copy link
Copy Markdown
Member

Yes, should fix it. Use like this:

from selenium.webdriver import Safari
from selenium.webdriver.safari.options import Options as SafariOptions

safari_options = SafariOptions()
driver = Safari(options=safari_options)
driver.quit()

@Alraku
Copy link
Copy Markdown

Alraku commented May 22, 2022

Actually I've had done that exactly the same before your answer and it hadn't worked.

conftest.py

@pytest.fixture(scope='class')
def setup(request, browser, url):
    if browser == "edge":
        driver = webdriver.Edge(service = Service(EdgeChromiumDriverManager().install()))
    elif browser == "chrome":
        driver = webdriver.Chrome(service = Service(ChromeDriverManager().install()))
    elif browser == "safari":
        safari_options = SafariOptions()
        driver = webdriver.Safari(
              service = Service(executable_path='/usr/bin/safaridriver'), options=safari_options)

    driver.maximize_window()
    request.cls.driver = driver
    
    yield driver
    driver.quit()
@pytest.mark.usefixtures("setup", "logger")
class TestSearchbox:

    @pytest.fixture()
    def class_setup(self):
        self.page_home = PageHome(self.driver)
        self.page_login = PageLogin(self.driver)
        self.driver.get(globals.base_url)


    @pytest.mark.order(1)
    @pytest.mark.parametrize("data_search_term, data_location, data_result", testdata_searchbox)
    def test_searchbox_term_one(self, class_setup, data_search_term, data_location, data_result):
        self.page_login.accept_privacy_dialog()
        self.page_home.search_phrase(search_term=data_search_term, location=data_location)
        assert data_result in self.driver.title, "Assertion Failed - Title does not match"

Warning still appears.

@titusfortner
Copy link
Copy Markdown
Member

Sure enough. The driver sets the value by default, then the superclass throws the warning not to set it.
I don't want to change the default behavior right now, though. We're pulling a bunch of this code out with the existing deprecations in 4.3 and that should fix all of this.

elgatov pushed a commit to elgatov/selenium that referenced this pull request Jun 27, 2022
* Add safari options

Include the Automatic Profiling and Automatic Inspection option to safarie options. Also add's the options to set browser name to Safari Technology Preview

* Add safari options unit tests

* Fix flake8 style error

There where some blank lines containing whitespaces which is against the flake8 style convention.

Co-authored-by: David Burns <[email protected]>
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.

[🚀 Feature]: Add Safari Options to Python

5 participants