def test_capabilities_for_selenium(self): browser_options = FirefoxOptions() browser_options.add_argument('--foo') browser_options.set_preference('foo', 'bar') options = SauceOptions(seleniumOptions=browser_options) options.build = 'Sample Build Name' expected_capabilities = { 'acceptInsecureCerts': True, 'browserName': 'firefox', 'browserVersion': 'latest', 'platformName': 'Windows 10', 'marionette': True, 'moz:firefoxOptions': { 'args': ['--foo'], 'prefs': { 'foo': 'bar' } }, 'sauce:options': { 'build': 'Sample Build Name' } } assert options.to_capabilities() == expected_capabilities
def test_sauce_options(self): sauce = SauceOptions() sauce.name = 'my-test' sauce.record_screenshots = False assert sauce.name == 'my-test' assert sauce.record_screenshots is False
def test_capabilities_for_sauce(self): sauce = SauceOptions() sauce.name = 'my-test' sauce.record_screenshots = False capabilities = sauce.to_capabilities() assert capabilities['sauce:options']['recordScreenshots'] is False assert capabilities['sauce:options']['name'] == 'my-test'
def test_w3c_options(self): sauce = SauceOptions() sauce.browser_name = 'safari' sauce.platform_name = 'macOS 10.14' sauce.accept_insecure_certs = True assert sauce.browser_name == 'safari' assert sauce.accept_insecure_certs is True assert sauce.platform_name == 'macOS 10.14'
def test_capabilities_for_selenium(self): browser_options = FirefoxOptions() browser_options.add_argument('--foo') browser_options.set_preference('foo', 'bar') sauce = SauceOptions(seleniumOptions=browser_options) capabilities = sauce.to_capabilities() assert capabilities['moz:firefoxOptions']['args'] == ['--foo'] assert capabilities['moz:firefoxOptions']['prefs'] == {'foo': 'bar'}
def test_setting_capabilities(self): # TODO create a conditional for this: file_location = r'./tests/options.yml' # if running on CI # file_location = r'options.yml' # If running locally with open(file_location) as file: yml = yaml.safe_load(file) prerun = { 'executable': 'http://url.to/your/executable.exe', 'args': ['--silent', '-a', '-q'], 'background': False, 'timeout': 120 } custom_data = {'foo': 'foo', 'bar': 'bar'} tags = ['foo', 'bar', 'foobar'] timeouts = {'implicit': 1, 'pageLoad': 59, 'script': 29} options = SauceOptions() options.merge_capabilities(yml.get("exampleValues")) assert options.browser_name == 'firefox' assert options.browser_version == '68' assert options.platform_name == 'macOS 10.13' assert options.accept_insecure_certs is True assert options.page_load_strategy == 'eager' assert options.set_window_rect is True assert options.unhandled_prompt_behavior == 'accept' assert options.strict_file_interactability is True assert options.timeouts == timeouts assert options.avoid_proxy is True assert options.build == 'Sample Build Name' assert options.capture_performance is True assert options.chromedriver_version == '71' assert options.command_timeout == 2 assert options.custom_data == custom_data assert options.extended_debugging is True assert options.idle_timeout == 3 assert options.iedriver_version == '3.141.0' assert options.max_duration == 300 assert options.name == 'Sample Test Name' assert options.parent_tunnel == 'Mommy' assert options.prerun == prerun assert options.priority == 0 assert options.public == 'team' assert options.record_logs is False assert options.record_screenshots is False assert options.record_video is False assert options.screen_resolution == '10x10' assert options.selenium_version == '3.141.59' assert options.tags == tags assert options.time_zone == 'San Francisco' assert options.tunnel_identifier == 'tunnelname' assert options.video_upload_on_pass is False
def driver(request): opts = SauceOptions() opts.name = request.node.name sauce = SauceSession(options=opts) sauce.start() yield sauce.driver # report results # use the test result to send the pass/fail status to Sauce Labs result = not request.node.rep_call.failed sauce.stop(result)
def driver(request): opts = SauceOptions() opts.name = request.node.name sauce = SauceSession(options=opts) sauce.start() yield sauce.driver # report results # use the test result to send the pass/fail status to Sauce Labs if request.node.rep_call.failed: sauce.setTestStatus("failed") else: sauce.setTestStatus("passed") sauce.stop()
def test_accepts_w3c_sauce_options_capabilities(self): browser_options = FirefoxOptions() browser_options.add_argument('--foo') browser_options.set_preference('foo', 'bar') options = {'maxDuration': 1, 'commandTimeout': 2} w3c_options = { 'acceptInsecureCerts': True, 'pageLoadStrategy': 'eager' } options.update(w3c_options) sauce = SauceOptions(seleniumOptions=browser_options, **options) assert sauce.browser_name == 'firefox' assert sauce.accept_insecure_certs is True assert sauce.page_load_strategy == 'eager' assert sauce.max_duration == 1 assert sauce.command_timeout == 2 assert sauce.selenium_options['moz:firefoxOptions'] == { 'args': ['--foo'], 'prefs': { 'foo': 'bar' } }
def test_accepts_browser_version_platform_name(self): sauce = SauceOptions(browserName='Chrome', browserVersion='75.0', platformName='macOS 10.13') assert sauce.browserName == 'chrome' assert sauce.browserVersion == '75.0' assert sauce.platformName == 'macOS 10.13'
def test_accepts_selenium_browser_options_instance(self): options = ChromeOptions() sauce = SauceOptions(options=options) assert sauce.browserName == 'chrome' assert sauce.browserVersion == 'latest' assert sauce.platformName == 'Windows 10'
def test_accepts_provided_options_instance(self): options = SauceOptions() session = SauceSession(options) assert session.options.browser_name == 'chrome' assert session.options.browser_version == 'latest' assert session.options.platform_name == 'Windows 10'
def driver(request): opts = SauceOptions(browserName=request.param) sauce = SauceSession(options=opts) sauce.start() yield sauce.driver sauce.stop()
def test_accepts_selenium_browser_capabilities_instance(self): options = DesiredCapabilities.CHROME.copy() sauce = SauceOptions(options=options) assert sauce.browserName == 'chrome' assert sauce.platformName == 'Windows 10' assert sauce.browserVersion == 'latest'
def test_accepts_selenium_browser_options_instance(self): options = FirefoxOptions() options.add_argument('--foo') options.set_preference('foo', 'bar') sauce = SauceOptions(seleniumOptions=options) assert sauce.browser_name == 'firefox' assert sauce.selenium_options['moz:firefoxOptions'] == {'args': ['--foo'], 'prefs': {'foo': 'bar'}}
def __init__(self, options=None, data_center='us-west', username=None, access_key=None): self.options = options if options else SauceOptions() self._username = username if username else SAUCE_USERNAME self._access_key = access_key if access_key else SAUCE_ACCESS_KEY self.data_center = data_center if data_center else 'us-west' self._remote_url = None self.driver = None
def test_default_build_name(self): os.environ['BUILD_TAG'] = ' ' os.environ['BUILD_NAME'] = 'BUILD NAME' os.environ['BUILD_NUMBER'] = '123' sauce = SauceOptions() assert sauce.build == 'BUILD NAME: 123' os.environ.pop("BUILD_TAG") os.environ.pop("BUILD_NAME") os.environ.pop("BUILD_NUMBER")
def test_accepts_Sauce_values(self): options = { "browserName": "chrome", "browserVersion": "75.0", "platformName": "Windows 10", "name": "sample test", "build": "sample build" } sauce = SauceOptions(options=options) assert sauce.options['sauce:options']['name'] == 'sample test' assert sauce.options['sauce:options']['build'] == 'sample build'
def test_accepts_w3c_values(self): options = { "browserName": "chrome", "sauce:options": { "browserName": "chrome", "browserVersion": "75.0", "platformName": "Windows 10" } } sauce = SauceOptions(options=options) assert sauce.browserName == 'chrome' assert sauce.browserVersion == '75.0' assert sauce.platformName == 'Windows 10'
def test_accepts_w3c_values_as_params(self): timeouts = {'implicit': 1, 'pageLoad': 59, 'script': 29} sauce = SauceOptions(acceptInsecureCerts=True, pageLoadStrategy='eager', setWindowRect=True, unhandledPromptBehavior='accept', strictFileInteractability=True, timeouts=timeouts) assert sauce.accept_insecure_certs is True assert sauce.page_load_strategy == 'eager' assert sauce.set_window_rect is True assert sauce.unhandled_prompt_behavior == 'accept' assert sauce.strict_file_interactability is True assert sauce.timeouts == timeouts
def test_capabilities_for_w3c(self): sauce = SauceOptions() sauce.browser_name = 'safari' sauce.platform_name = 'macOS 10.14' sauce.accept_insecure_certs = True capabilities = sauce.to_capabilities() assert capabilities['acceptInsecureCerts'] is True assert capabilities['browserName'] == 'safari' assert capabilities['browserVersion'] == 'latest' assert capabilities['sauce:options']['build'] is not None
def test_accepts_w3c_values_with_dict(self): timeouts = {'implicit': 1, 'pageLoad': 59, 'script': 29} options = { 'acceptInsecureCerts': True, 'pageLoadStrategy': 'eager', 'setWindowRect': True, 'unhandledPromptBehavior': 'accept', 'strictFileInteractability': True, 'timeouts': timeouts } sauce = SauceOptions(**options) assert sauce.accept_insecure_certs is True assert sauce.page_load_strategy == 'eager' assert sauce.set_window_rect is True assert sauce.unhandled_prompt_behavior == 'accept' assert sauce.strict_file_interactability is True assert sauce.timeouts == timeouts
def __init__(self, data_center='us', username=None, access_key=None, options=None): # TODO: flesh this out self.options = options if options else SauceOptions() self._username = username if username else SAUCE_USERNAME self._access_key = access_key if access_key else SAUCE_ACCCESS_KEY self._data_center = data_center if data_center.lower() == 'eu': self.remote_url = EU_SAUCE_DC_URL elif data_center.lower() == 'us': self.remote_url = US_SAUCE_DC_URL else: raise KeyError( "Invalid Data Center value, please select from 'us' or 'eu'") self.driver = {}
def test_accepts_sauce_values_with_dict(self): options = {'maxDuration': 1, 'commandTimeout': 2, 'idleTimeout': 3, 'name': 'foo', 'build': 'bar', 'tags': ['foo', 'bar'], 'parentTunnel': 'bar', 'tunnelIdentifier': 'foobar', 'screenResolution': '10x10', 'timeZone': 'Foo', 'extendedDebugging': True, 'capturePerformance': True, 'recordVideo': False, 'videoUploadOnPass': False, 'recordScreenshots': False, 'recordLogs': False} sauce = SauceOptions(**options) assert sauce.max_duration == 1 assert sauce.command_timeout == 2 assert sauce.idle_timeout == 3 assert sauce.name == 'foo' assert sauce.build == 'bar' assert sauce.tags == ['foo', 'bar'] assert sauce.parent_tunnel == 'bar' assert sauce.tunnel_identifier == 'foobar' assert sauce.screen_resolution == '10x10' assert sauce.time_zone == 'Foo' assert sauce.extended_debugging is True assert sauce.capture_performance is True assert sauce.record_video is False assert sauce.video_upload_on_pass is False assert sauce.record_screenshots is False assert sauce.record_logs is False
def test_defaults(self): sauce = SauceOptions('MicrosoftEdge') assert sauce.browser_name == 'MicrosoftEdge' assert sauce.browser_version == 'latest' assert sauce.platform_name == 'Windows 10'
def test_add_build_name(self): sauce = SauceOptions() sauce.build = 'my-build' assert "my-build" == sauce.build
def test_add_test_name(self): sauce = SauceOptions() sauce.name = 'my-test' assert "my-test" == sauce.name
def test_default_test_name(self): sauce = SauceOptions() assert sauce.name is not None
def test_default_build_value(self): sauce = SauceOptions() assert sauce.build is not None
def test_defaults_to_win10_chrome_latest(self): sauce = SauceOptions() assert sauce.browserName == 'chrome' assert sauce.browserVersion == 'latest' assert sauce.platformName == 'Windows 10'