def _saucelabs_test_result(self): """SauceLabs has no way to determine whether test passed or failed automatically, so we explicitly 'tell' it """ if settings.browser == 'saucelabs' and sauceclient: sc = sauceclient.SauceClient( settings.saucelabs_user, settings.saucelabs_key) passed = True status = 'passed' if (len(self._outcome.errors) > 0 and self in self._outcome.errors[-1]): passed = False status = 'failed' if (len(self._outcome.skipped) > 0 and self in self._outcome.skipped[-1]): passed = None status = 'complete' LOGGER.debug( 'Updating SauceLabs job "%s": name "%s" and status "%s"', self.browser.session_id, str(self), status ) sc.jobs.update_job( self.browser.session_id, name=str(self), passed=passed)
def test_get_status_with_auth(self): sc = sauceclient.SauceClient( SAUCE_USERNAME, SAUCE_ACCESS_KEY, ) status = sc.information.get_status() self.assertIsInstance(status, dict) self.assertIn('service_operational', status) self.assertIn('status_message', status) self.assertIn('wait_time', status) self.assertTrue(status['service_operational'])
def setup_sauce_browser(context): """ Use saucelabs remote webdriver. Has side effects on the passed in behave context. :param context: the behave context :return: none, but has side effects. Adds properties "sauce" and "browser" to context. """ # based on http://saucelabs.com/examples/example.py username = os.environ.get('SAUCE_USERNAME') access_key = os.environ.get('SAUCE_ACCESS_KEY') circle_build = os.environ.get('CIRCLE_BUILD_NUM') circle_node = os.environ.get('CIRCLE_NODE_INDEX') tunnel_id = "{build}-{node}".format(build=circle_build, node=circle_node) context.sauce = sc.SauceClient(username, access_key) sauce_url = "http://{username}:{access_key}@ondemand.saucelabs.com:80/wd/hub".format( username=username, access_key=access_key) profile = webdriver.FirefoxProfile() if "download_csv" in context.tags: # Let csv files be downloaded automatically. Can be accessed using context.download_dir context.download_dir = tempfile.mkdtemp() profile.set_preference("browser.download.folderList", 2) profile.set_preference("browser.download.manager.showWhenStarting", False) profile.set_preference("browser.download.dir", context.download_dir) profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv") context.browser = webdriver.Firefox( firefox_profile=profile ) # Use local browser for this particular test else: desired_capabilities = DesiredCapabilities.FIREFOX.copy() desired_capabilities["tunnelIdentifier"] = tunnel_id try: context.browser = webdriver.Remote( desired_capabilities=desired_capabilities, browser_profile=profile, command_executor=sauce_url) except ( WebDriverException, socket.timeout ): # socket.timeout thrown occasionally, Selenium doesn't handle it print( "Couldn't establish a connection to saucelabs. Using a local Firefox WebDriver instance." ) del context.sauce context.browser = webdriver.Firefox(firefox_profile=profile)
def _finalize_saucelabs_browser(self, passed): """SauceLabs has no way to determine whether test passed or failed automatically, so we explicitly 'tell' it. Note: should not be called directly, use :meth:`finalize` instead. :param bool passed: Bool value indicating whether test passed or not. """ client = sauceclient.SauceClient(settings.selenium.saucelabs_user, settings.selenium.saucelabs_key) LOGGER.debug('Updating SauceLabs job "%s": name "%s" and status "%s"', self._webdriver.session_id, self.test_name, 'passed' if passed else 'failed') kwargs = {'passed': passed} # do not pass test name if it's not set if self.test_name: kwargs.update({'name': self.test_name}) client.jobs.update_job(self._webdriver.session_id, **kwargs)
import sys #importing the Appium Python bindings for Selenium Webdriver from the python Appium module. from appium import webdriver #importing the Selenium Python bindings for Selenium Webdriver from the python Selenium module. from selenium import webdriver #importing the sauceclient which is a Python client library, used for accessing the Sauce Labs REST API to retrieve and update information about resources. import sauceclient import json import new #Retreiving enviroment variables SAUCE_USERNAME = os.environ.get('SAUCE_USERNAME') SAUCE_ACCESS_KEY = os.environ.get('SAUCE_ACCESS_KEY') #Credentials for SauceClient test_result = sauceclient.SauceClient(SAUCE_USERNAME, SAUCE_ACCESS_KEY) class AppiumMobileWebAppTest(unittest.TestCase): def setUp(self): self.desired_capabilities = {} self.desired_capabilities['platformName'] = 'Android' self.desired_capabilities['platformVersion'] = '5.0' self.desired_capabilities['browserName'] = 'browser' self.desired_capabilities['deviceName'] = 'Android Emulator' self.desired_capabilities['appium-version'] = '1.3.6' self.desired_capabilities['name'] = 'Android Example from Jenkins' self.driver = webdriver.Remote(command_executor = ('http://' + SAUCE_USERNAME + ':' + SAUCE_ACCESS_KEY + '@ondemand.saucelabs.com:80/wd/hub'), desired_capabilities = self.desired_capabilities) self.driver.implicitly_wait(30)
def setUp(self): self.sc = sauceclient.SauceClient('sauce-username', 'sauce-access-key')
def setUp(self): self.sc = sauceclient.SauceClient( SAUCE_USERNAME, SAUCE_ACCESS_KEY, )
def setUp(self): self.sc = sauceclient.SauceClient()
host = os.environ.get('SELENIUM_HOST') port = os.environ.get('SELENIUM_PORT') platform = os.environ.get('SELENIUM_PLATFORM') version = os.environ.get('SELENIUM_VERSION') browser = os.environ.get('SELENIUM_BROWSER') device = os.environ.get('SELENIUM_DEVICE') deviceType = os.environ.get('SELENIUM_DEVICE_TYPE') driver = os.environ.get('SELENIUM_DRIVER') onDemandBrowsers = os.environ.get('SAUCE_ONDEMAND_BROWSERS') url = os.environ.get('SELENIUM_URL') userName = os.environ.get('SAUCE_USER_NAME') apiKey = os.environ.get('SAUCE_API_KEY') startingUrl = os.environ.get('SELENIUM_STARTING_URL') #Credentials for SauceClient test_result = sauceclient.SauceClient(userName, apiKey) print (host,port,platform,version,browser,device,deviceType,driver,onDemandBrowsers,url,userName,apiKey,startingUrl) class AppiumMobileWebAppTest(unittest.TestCase): def setUp(self): # When you select the platforms/browser in the plugin the plugin will set those values to a series of environment variables. # You need to point your desired capabilities to these enviroment variables. Be careful, some of them can't be properly set by the plugin, so you will have to set it yourself. # SELENIUM_HOST - The hostname of the Selenium server # SELENIUM_PORT - The port of the Selenium server # SELENIUM_PLATFORM - The operating system of the selected browser # SELENIUM_VERSION - The version number of the selected browser # SELENIUM_BROWSER - The browser name of the selected browser. # SELENIUM_DEVICE - The device name of the selected browser (only available for mobile browsers)