Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def browserstack_local(binary, key, identifier, command):
process = await asyncio.create_subprocess_exec(
binary,
'--key', key,
'--local-identifier', identifier,
'--daemon', command,
)
_, stderr = await process.communicate()
if process.returncode != 0:
raise Exception(stderr)
@attr.s
class BrowserStackLocal:
service: services.Service = attr.ib()
identifier: str = attr.ib(init=False, repr=False)
api_key: str = attr.ib(init=False, repr=False)
binary: str = attr.ib(init=False)
process: Process = attr.ib(default=None, repr=False)
def __attrs_post_init__(self):
self.identifier = os.environ['BROWSERSTACK_LOCAL_IDENTIFIER']
self.api_key = os.environ['BROWSERSTACK_API_KEY']
self.binary = os.environ.get('BROWSERSTACK_BINARY', 'BrowserStackLocal')
async def start(self) -> WebDriver:
await browserstack_local(self.binary, self.api_key, self.identifier, 'start')
webdriver: WebDriver = await self.service.start()
webdriver.closers.append(
partial(browserstack_local, self.binary, self.api_key, self.identifier, 'stop')
def service():
service = get_instance(os.environ['ARSENIC_SERVICE'], services)
if os.environ.get('BROWSERSTACK_LOCAL_IDENTIFIER', None):
if not os.environ.get('BROWSERSTACK_API_KEY', False):
raise pytest.skip('BROWSERSTACK_API_KEY not set')
service = BrowserStackLocal(service)
return service
async def hello_world():
service = services.Geckodriver(binary=GECKODRIVER)
browser = browsers.Firefox()
async with get_session(service, browser) as session:
await session.get("https://images.google.com/")
search_box = await session.wait_for_element(5, "input[name=q]")
await search_box.send_keys("Cats")
await search_box.send_keys(keys.ENTER)
await asyncio.sleep(10)
async def wrapper():
gecko = services.Geckodriver()
ff = browsers.Firefox()
async with RunApp() as base_url, get_session(gecko, ff, base_url) as session:
return await coro(session)