HENNGE / arsenic

Async WebDriver implementation for asyncio and asyncio-compatible frameworks
Other
350 stars 54 forks source link

API question #1

Closed tarekziade closed 7 years ago

tarekziade commented 7 years ago

I am wondering if we could simplify the API usage by providing a high level class that does everything one would expect when running a Firefox session.

Something like:

async with FirefoxSession(*some, **options) as firefox:
    await firefox.get('http://example.com')

what do you think?

tarekziade commented 7 years ago

Here's a working example

https://github.com/tarekziade/molosonic/blob/master/loadtest.py

notice that I had to hack around the context manager. It's nice to have context managers, but I think it should not be mandatory to use the classes.

I like how aiohttp does it. e.g. you can use the Session objects in regular code by initializing it and closing it manually, or if you want you can use the context manager so it does that for you.

tarekziade commented 7 years ago

Turned out it was my lack of understanding of the implementation. After more work, I was able to use it without context manager. Sorry ;)

https://github.com/tarekziade/molosonic/blob/master/loadtest.py#L23-L53

The Firefox class I have implemented would be the high level API I was talking about

ojii commented 7 years ago

The split between driver/session which leads to a kind of low level API was initially done because I (wrongly) assumed you could have multiple sessions per driver. At least for Geckodriver that seems to not be the case, so I'm considering adding a higher level "just give me a browser session" API that combines the two.

ojii commented 7 years ago

api has changed to higher level, closing this.