Saucelabs: Can we use Dynamic Device Allocation using Virtual devices?

38 Views Asked by At

We're currently encountering the error below and we figured out it's because the device that we are trying to use is currently not available.

HOOK-ERROR in before_scenario: MaxRetryError: HTTPConnectionPool(host='ondemand.us-west-1.saucelabs.com', port=80): Max retries exceeded with url: ***ondemand.us-west-1.saucelabs.com/wd/hub/session/784aec08b0024b828d2d3e091eb5fdc2?ref=9601c9d4cb694b238fcec5ede61b960f (Caused by ResponseError('too many redirects'))

We're trying to do a Dynamic device allocation but for Virtual devices in Saucelabs. But we're getting the error below:

HOOK-ERROR in before_scenario: SessionNotCreatedException: Message: There is no device that matches your criteria. DesiredCapabilities: ***"capabilities":***"firstMatch":[***"appium:appActivity":"com.quipper.school.assignment.ui.SplashActivity","platformName":"Android","appium:deviceName":".*Google.*","appium:automationName":"UiAutomator2","appium:platformVersion":"11","appium:app":"storage:filename\u003dapp-global-rc-July-5.apk","appium:appPackage":"com.quipper.school.assignment.rc","sauce:options":***"name":"Android login and signup + @login,@sign_up07-12 01:01","sessionCreationRetry":"2","sessionCreationTimeout":"3000"***]***
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'Sauce Labs RDC', ip: 'N/A', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.176+', java.version: '11.0.19'
Driver info: driver.version: unknown

We're using devicename : ['Google Pixel 3 GoogleAPI Emulator'] as our device and we wanted to have a family of available Google Pixel devices with Android 11 to use. I can't seem to figure out how to assign it dynamically. Tried ['.*Google.*'] , ['.*Google Pixel.*'], ['.*Google.*Pixel.*GoogleAPI.*Emulator.*'] but still nothing works.

Here is our current environment.py:

import os
import time
from appium import webdriver
from selenium.common import InvalidSessionIdException
from app.application import Application


def before_scenario(context, scenario):

    sauce_username = os.environ["SAUCE_USERNAME"]
    sauce_access_key = os.environ["SAUCE_ACCESS_KEY"]

    desired_caps = {
        'platformName': os.environ["platformname"],  # os
        'platformVersion': os.environ["platformversion"],  # version
        'deviceName': os.environ["devicename"],  # device name
        'automationName': os.environ["automationname"],
        'appPackage': os.environ["apppackage"],
        'appActivity': os.environ["appactivity"],
        'app': os.environ["app"],
        'sauce:options': {  # Sauce custom capabilities
            "sessionCreationRetry": "2",
            "sessionCreationTimeout": "3000",
            "name": os.environ["jobname"] + time.strftime("%m-%d %H:%M")
        }
    }

    # launch app
    context.driver = webdriver.Remote("http://{}:{}@ondemand.us-west-1.saucelabs.com/wd/hub".format(sauce_username, sauce_access_key), desired_caps)
    time.sleep(30)
    if context.driver.session_id is None:
        context.driver = webdriver.Remote("http://{}:{}@ondemand.us-west-1.saucelabs.com/wd/hub".format(sauce_username, sauce_access_key), desired_caps)
    else:
        context.driver.implicitly_wait(20)
        context.app = Application(context.driver)


def after_scenario(context, scenario):
    if hasattr(context, 'driver') and context.driver is not None:
        context.driver.save_screenshot("screenshot" + time.strftime("%y-%m-%d %H%M") + ".png")
        status = str(scenario.status)
        context.driver.execute_script('sauce:job-result=' + status)
        context.driver.quit()
        try:
            if context.driver.session_id:
                context.driver.quit()
        except InvalidSessionIdException:
            return
    else:
        return True
0

There are 0 best solutions below