示例#1
0
    def test_defaults_to_west(self):
        session = SauceSession()

        session.start()

        assert session.driver.session_id
        assert "us-west-1" in session.remote_url
    def test_raises_exception_if_no_access_key_set(self, monkeypatch):
        monkeypatch.delenv("SAUCE_ACCESS_KEY")

        session = SauceSession()

        with pytest.raises(KeyError):
            session.start()
    def test_raises_exception_if_no_username_set(self, monkeypatch):
        monkeypatch.delenv("SAUCE_USERNAME")

        session = SauceSession()

        with pytest.raises(KeyError):
            session.start()
示例#4
0
    def test_runs_on_eu_central(self):
        session = SauceSession()
        session.data_center = 'eu-central'

        session.start()

        assert session.driver.session_id
        assert "eu-central-1" in session.remote_url
    def test_sauce_session_ended(self, mocker):
        sauce_session = SauceSession()
        mocker.patch.object(sauce_session, 'create_driver')

        driver = sauce_session.start()
        mocker.patch.object(driver, 'quit')

        sauce_session.stop(True)
        driver.quit.assert_called_once()
示例#6
0
    def test_runs_on_us_east(self):
        options = SauceOptions()
        options.platform_name = 'Linux'

        session = SauceSession(options)
        session.data_center = 'us-east'

        session.start()

        assert session.driver.session_id
        assert "us-east-1" in session.remote_url
    def test_failing_case(self, mocker):
        sauce_session = SauceSession()
        mocker.patch.object(sauce_session, 'create_driver')

        driver = sauce_session.start()
        mocker.patch.object(driver, 'execute_script')

        sauce_session.stop(False)

        driver.execute_script.assert_called_once_with(
            'sauce:job-result=failed')
示例#8
0
    def test_creates_session(self):
        # 1. Create Session object with the desired Data Center
        session = SauceSession(data_center='eu-central')

        # 2. Start Session to get the Driver
        driver = session.start()

        # 3. Use the driver in your tests just like normal
        driver.get('https://www.saucedemo.com/')

        # 4. Stop the Session with whether the test passed or failed
        session.stop(True)
class SauceLabs(object):
    def __init__(self):
        self.sauce = {}

    def start_session(self):
        self.sauce = SauceSession()
        return self.sauce.start()

    def go_to_demo(self):
        self.sauce.driver.get(BASE_TEST_URL)

    def title_is_correct(self):
        assert "Swag" in self.sauce.driver.title

    def stop_session(self):
        self.sauce.stop(True)
示例#10
0
    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'
示例#11
0
    def test_creates_session(self):
        # 1. Create a SauceOptions instance with the 3 primary parameters
        sauceOptions = SauceOptions(browserName='firefox',
                                    browserVersion='73.0',
                                    platformName='Windows 8')

        # 2. Create Session object with SauceOptions object instance
        session = SauceSession(sauceOptions)

        # 3. Start Session to get the Driver
        driver = session.start()

        # 4. Use the driver in your tests just like normal
        driver.get('https://www.saucedemo.com/')

        # 5. Stop the Session with whether the test passed or failed
        session.stop(True)
    def test_creates_session(self):
        # 1. Create a SauceOptions instance with Sauce Labs Specific Options
        sauceOptions = SauceOptions(extendedDebugging=True,
                                    idleTimeout=100,
                                    timeZone='Alaska')

        # 2. Create Session object with SauceOptions object instance
        session = SauceSession(sauceOptions)

        # 3. Start Session to get the Driver
        driver = session.start()

        # 4. Use the driver in your tests just like normal
        driver.get('https://www.saucedemo.com/')

        # 5. Stop the Session with whether the test passed or failed
        session.stop(True)
示例#13
0
    def test_creates_a_session_on_sauce_labs(self, mocker):
        default_url = 'https://*****:*****@ondemand.us-west-1.saucelabs.com:443/wd/hub'
        expected_caps = {
            'browserName': 'chrome',
            'browserVersion': 'latest',
            'platformName': 'Windows 10',
            'sauce:options': {
                'build': 'TEST BUILD: 11'
            }
        }

        sauce_session = SauceSession()
        mocker.patch.object(sauce_session, 'create_driver')

        sauce_session.start()

        sauce_session.create_driver.assert_called_once_with(
            default_url, expected_caps)
示例#14
0
    def test_creates_session(self):

        # 1. Create Selenium Browser Options instance
        browserOptions = FirefoxOptions()
        browserOptions.add_argument('--foo')

        # 2. Create Sauce Options object with the Browser Options object instance
        sauceOptions = SauceOptions(seleniumOptions=browserOptions)

        # 3. Create Session object with SauceOptions object instance
        session = SauceSession(sauceOptions)

        # 4. Start Session to get the Driver
        driver = session.start()

        # 5. Use the driver in your tests just like normal
        driver.get('https://www.saucedemo.com/')

        # 6. Stop the Session with whether the test passed or failed
        session.stop(True)
示例#15
0
def driver(request):
    opts = SauceOptions(request.param)
    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)
示例#16
0
class BindingsLibrary(object):

    def __init__(self):
        self.sauce = {}


    def start_session(self, browser_name, test_name):
        opts = SauceOptions(browser_name)
        opts.name = test_name
        self.sauce = SauceSession(options=opts)
        self.sauce.start()


    def open_login_page(self):
        self.sauce.driver.get(BASE_TEST_URL)


    def end_session(self, result):
        if str(result) == 'PASS':
            self.sauce.stop(True)
        else:
            self.sauce.stop(False)

    
    def login_as_standard_user(self):
        self.sauce.driver.find_element_by_id("user-name").send_keys("standard_user")
        self.sauce.driver.find_element_by_id("password").send_keys("secret_sauce")
        self.sauce.driver.find_element_by_css_selector(".btn_action").click()


    def login_as_invalid_user(self):
        self.sauce.driver.find_element_by_id("user-name").send_keys("invalid")
        self.sauce.driver.find_element_by_id("password").send_keys("invalid")
        self.sauce.driver.find_element_by_css_selector(".btn_action").click()

    
    def is_login_error_displayed(self):
        assert self.sauce.driver.find_element_by_css_selector('.error-button').is_displayed()

    
    def is_on_inventory_page(self):
        assert self.sauce.driver.find_element_by_id('shopping_cart_container').is_displayed()
示例#17
0
    def test_raises_exception_if_data_center_is_invalid(self):
        session = SauceSession()

        with pytest.raises(ValueError):
            session.data_center = 'invalid'
示例#18
0
"""Most basic example of using Simple Sauce.

Here we start a session on Sauce, perform some actions then close the session.
"""
from saucebindings.session import SauceSession


session = SauceSession()

session.start()
session.driver.get("https://www.saucedemo.com")

result = "Swag" in session.driver.title

session.stop(result)
示例#19
0
 def start_session(self, browser_name, test_name):
     opts = SauceOptions(browser_name)
     opts.name = test_name
     self.sauce = SauceSession(options=opts)
     self.sauce.start()
示例#20
0
    def test_generates_default_options_instance_if_not_provided(self):
        session = SauceSession()

        assert session.options.browser_name == 'chrome'
        assert session.options.browser_version == 'latest'
        assert session.options.platform_name == 'Windows 10'
 def start_session(self):
     self.sauce = SauceSession()
     return self.sauce.start()
示例#22
0
    def test_overrides_default_value_for_data_center(self):
        session = SauceSession()

        session.data_center = 'eu-central'

        assert "eu-central-1" in session.remote_url
示例#23
0
    def test_user_can_override_default_url(self):
        session = SauceSession()
        session.remote_url = 'https://*****:*****@foobar.com/wd/hub'

        assert session.remote_url == 'https://*****:*****@foobar.com/wd/hub'
示例#24
0
    def test_defaults_to_us_west_data_center(self):
        session = SauceSession()

        assert "us-west-1" in session.remote_url