alfred82santa / whalesong

Whalesong is an asyncio python library to manage WebApps remotely. Currently WhatsappWeb is implemented
https://whalesong.readthedocs.io
MIT License
50 stars 19 forks source link

Waiting for status to be CONNECTED #81

Closed parthibd closed 5 years ago

parthibd commented 5 years ago

Is there a way to wait for the driver status to be CONNECTED possibly with a timeout ?

alfred82santa commented 5 years ago
async def wait_until_connect(driver):
        async for evt in driver.stream.monitor_field('stream'):
            if evt['value'] == Stream.Stream.CONNECTED:
                return
parthibd commented 5 years ago

Thanks!

parthibd commented 5 years ago

I am trying to do this

await driver.stop()
await driver.start()

Its throwing me selenium.common.exceptions.InvalidSessionIdException: Message: Tried to run command without establishing a connection . Why is that ?

alfred82santa commented 5 years ago

Are you trying to stop before start?

parthibd commented 5 years ago

No I am not . I started the driver using await driver.start() .

alfred82santa commented 5 years ago

When it fails? When you stop it or when you try to start again?

parthibd commented 5 years ago

When I try to stop it . Here is the initialization code


@middleware
async def run_before_every_request(request, handler):
    client_id = request.headers["client-id"]
    api_key = request.headers["api-key"]
    if api_key != API_KEY:
        return web.json_response({"message": "Please provide correct API key", "status": False}, status=401)
    if client_id not in drivers.keys():
        async_loop = asyncio.get_event_loop()
        profile_path = os.path.join(FIREFOX_PROFILES_PATH, client_id)
        if not os.path.exists(profile_path):
            os.makedirs(profile_path)
        driver = whalesong.Whalesong(
            profile=profile_path,
            loadstyles=True,
            loop=async_loop
        )
        await driver.start()
        request["driver"] = driver
        drivers[client_id] = driver
    else:
        request["driver"] = drivers[client_id]
    return await handler(request)
alfred82santa commented 5 years ago

That error is because connection with Selenium is lost. You initialitation looks ok. I can not see more.

parthibd commented 5 years ago

What can I do to resolve it ? Bug within whalesong ?

alfred82santa commented 5 years ago

I don't know. It could be a problem with your code. Can you test an script which starts and stops whalesong? If it fails it is a bug in Whalesong, otherwise it is your code.

parthibd commented 5 years ago

Here is my test code


import asyncio
import os

import whalesong

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
PROFILE_PATH = os.path.join(BASE_DIR, 'test-profile')
async_loop = asyncio.get_event_loop()
driver: whalesong.Whalesong = whalesong.Whalesong(
    profile=PROFILE_PATH,
    loadstyles=True,
    loop=async_loop
)

async def start():
    await driver.start()
    await driver.stop()

if __name__ == '__main__':
    driver.loop.run_until_complete(start())

Same exception.

alfred82santa commented 5 years ago

Ok, create a bug