seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
4.67k stars 929 forks source link

Setting the browser via shortcut in pytest.main() isn't working #1703

Closed mdmintz closed 1 year ago

mdmintz commented 1 year ago

Setting the browser via shortcut in pytest.main() isn't working

To reproduce, run the following script with python:

from seleniumbase import BaseCase

if __name__ == "__main__":
    from pytest import main
    main([__file__, "--edge", "-s"])

class EdgeTests(BaseCase):
    def test_edge(self):
        if self.browser != "edge":
            self.open("data:,")
            print("\n  This test is only for Microsoft Edge (Chromium)!")
            print('  (Run this test using "--edge" or "--browser=edge")')
            self.skip('Use "--edge" or "--browser=edge"')
        if self.headless:
            self.open("data:,")
            print("\n  This test is NOT designed for Headless Mode!")
            self.skip('Do NOT use "--headless" with this test!')
        self.open("edge://settings/help")
        self.highlight('div[role="main"]')
        self.highlight('img[srcset*="logo"]')
        self.assert_text("Microsoft Edge", 'img[srcset*="logo"] + div')
        self.highlight('img[srcset*="logo"] + div span:nth-of-type(1)')
        self.highlight('img[srcset*="logo"] + div span:nth-of-type(2)')
        self.highlight('span[aria-live="assertive"]')
        self.highlight('a[href*="chromium"]')

The --edge option wasn't taking effect from the pytest.main() call at the top when run with python. Instead, the default browser, (Chrome), was being used instead.

mdmintz commented 1 year ago

Fixed in 4.12.1 - https://github.com/seleniumbase/SeleniumBase/releases/tag/v4.12.1