New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for executing asynchronous JavaScript #11
Conversation
@StephenCleary Any thoughts? |
Sorry, it's been a crazy week! I'll try to take a look at this tonight. |
Hey, I understand as I have those too. 😄 In fact, this past one was just that. |
I agree fully with the naming decision. The IntelliSense ordering is unfortunate, but it is still the best option. Set-only properties and unintuitive "method pairs" are not great. What do you think about adding a timeout parameter (with a reasonable default) and always having |
A parameter would be odd because it would continue to remain in effect after the method returns. Since we can't read the timeout, we can't restore it to the previous value after the method is done executing.
Sorry, but what do you mean by method pairs? I agree |
True, but if they don't drop to the Selenium layer, they won't ever see that effect. Each time they call the method, the parameter is re-set.
Like the user sees A read/write property would be better than a write-only property or a method pair, but it could get out of sync with the Selenium layer. Selenium's API was designed around unit testing, and I think it makes sense in BrowserBoss to have an API that is designed around scripting. |
Then again, that only matters for someone who wants to drop to the Selenium layer, right? Like the parameter, the property's value would be used to set the timeout before each call into Perhaps I'm trying too hard to keep parity with |
Right now, public static dynamic AsyncScript(string script, params object[] args) I'm guessing for the parameter version, we'd add an overload with the timeout parameter coming first? Keeping public static dynamic AsyncScript(TimeSpan timeout, string script, params object[] args) |
FYI, I just discovered while working on another project that Selenium 3.1 introduces a read-write property called |
I believe that the What I'd really like to see is a |
This is the PR for #10.
It adds
AsyncScript
toBrowser
andBoss
. I called the methodAsyncScript
and notScriptAsync
to highlight that the script has to be asynchronous instead of the execution of the method itself being asynchronous. One would also expect that a method calledScriptAsync
would returnTask<dynamic>
and that's not the case here. What's more,AsyncScript
lines up nicely withExecuteAsyncScript
fromIJavaScriptExecutor
. The one downside of this, however, is thatScriptAsync
doesn't sit there next toScript
in the IntelliSense pop-up.I also added
Browser.ScriptTimeout
as a set-only property since there is no way to read out the value from the driver today (unless I missed something). We could make it readable nonetheless by caching the last value set through the property so that it can be returned later in the getter method. We would also have to assume a default of 0, which is what it is today but it could mislead if it changes in the future. To avoid assuming anything, an option would be forScriptTimeout
be aTimeSpan?
that starts out asnull
, meaning no value was set via the property. Finally, if a set-only property seems odd then we could just turn it into a method. Both would be the most accurate representation of the what's really there today.Since script timeout is 0 by default in the driver, the experience isn't very nice because the first attempt to use
AsyncScript
fails. You have to set the timeout first viaBrowser.ScriptTimeout
. That seems against the spirit of the project, which is to make the interface super simple. So my question is, shouldAsyncScript
set the timeout to some reasonable default of 30 seconds if the timeout has never been set before?Let me know your thoughts on the above points.