Skip to content
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

[java] have overloaded constructors to have configurable connect and read timeouts while instantiating WebDriver object #11532

Merged
merged 41 commits into from
Mar 21, 2023

Conversation

code-with-abdullah
Copy link
Contributor

Currently the code only has 10 seconds set as connect timeout and 3 minutes set as read timeout.

This fix will allow this to configurable at constructor level i.e you now have a separate constructor for ChromeDriver that supports read timeout and connect timeout as well.

@CLAassistant
Copy link

CLAassistant commented Jan 10, 2023

CLA assistant check
All committers have signed the CLA.

@titusfortner
Copy link
Member

I don't love the idea of creating new constructors for each of the drivers, and if we do go that route, we should implement the full ClientConfig rather than just these 2 values. Also, this is missing Edge & IE support, and for this kind of implementation we'd want to set default values and have the old constructors consume the new constructor using those values. (important because of the upcoming changes to driver classes with DriverFinder implementation).

@diemol
Copy link
Member

diemol commented Jan 11, 2023

+1 to what @titusfortner says. Timeouts can be set already through the builder, we are figuring out how to avoid the user needing to set a default value.

@code-with-abdullah
Copy link
Contributor Author

@titusfortner @diemol First of all thanks for your feedback.

As rightly pointed out this was missing Edge and IE support initially. That has now been updated.
For the point that we should have default values and consume those in old constructors, java does not support default value constructors, can you please guide on how this can be addressed?
Timeouts can be set already through the builder but I could not find a way that would allow end user to create an instance of ChromeDriver with these configurations. This implementation can be used to further enhance the builder method in all classes to provide support for timeout at the time of driver object instantiation.

@titusfortner
Copy link
Member

titusfortner commented Jan 11, 2023

I generally agree that even though it *can be done with the builder, you aren't working with a ChromeDriver instance, but an augmented RemoteWebDriver instance, which isn't as straightforward, and it would be nice to support it directly.

But, I don't think we just want to tack on extra timeout values. Instead of:

  public ChromeDriver(ChromeDriverService service, ChromeOptions options, int connectTimeoutSeconds, int readTimeoutSeconds) {  }

we should figure out how to implement:

  public ChromeDriver(ChromeDriverService service, ChromeOptions options, ClientConfig clientConfig) {  }

It actually looks like that might be easier to implement? I'm not following some of the changes being made here, so I'd need to pull it and test it to make sure it is actually doing what we want.

What I meant by using defaults and consume is something like:

DEFAULT_CONNECT_TIMEOUT = Duration.ofSeconds(10);
DEFAULT_READ_TIMEOUT = Duration.ofMinutes(3);

  public ChromeDriver(ChromeDriverService service, ChromeOptions options) {
this(service, options, DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT);
}

  public ChromeDriver(ChromeDriverService service, ChromeOptions options, int connectTimeoutSeconds, int readTimeoutSeconds) {
    super(new ChromeDriverCommandExecutor(service), Require.nonNull("Driver options", options), ChromeOptions.CAPABILITY, connectTimeoutSeconds, readTimeoutSeconds);
    casting = new AddHasCasting().getImplementation(getCapabilities(), getExecuteMethod());
    cdp = new AddHasCdp().getImplementation(getCapabilities(), getExecuteMethod());
  }

One constructor uses the other with a default instead of duplicating logic. That way when I go to make a change in the constructor logic, I only have to do it in one place.

This is actually easier if we use ClientConfig, though, because we don't need default constants, we can just new up an instance:

  public ChromeDriver(ChromeDriverService service, ChromeOptions options) {
this(service, options, ClientConfig.defaultConfig());
}

@code-with-abdullah code-with-abdullah changed the title re #11158 - Added over riden constructors to have configurable connect and read timeouts re #11158 - Have overloaded constructors to have configurable connect and read timeouts while instantiating WebDriver object in Java Jan 15, 2023
Copy link
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have been chatting internally and we think it makes sense to add the extra constructor to define the timeout locally. However, we'd prefer if a ClientConfig is passed instead of the two variables. @krmahadevan has helped to illustrate this in #11545, perhaps you can get inspiration from there and get this PR in shape. If you need more help, please reach out to us in the Slack channel #selenium-tlc, https://www.selenium.dev/support/.

Thank you for putting this together.

@code-with-abdullah
Copy link
Contributor Author

Hi @diemol

Thanks for your feedback!
I shall update this PR.

@diemol
Copy link
Member

diemol commented Jan 16, 2023

Hi @diemol

Thanks for your feedback! I shall update this PR.

Perfect, let us know if you need any help.

@code-with-abdullah
Copy link
Contributor Author

Dear @diemol.
I have updated the PR as per your request. Please review and let me know if there are any changes needed and I will integrate those as soon as possible.

Copy link
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some additional comments, @code-with-abdullah.

@code-with-abdullah
Copy link
Contributor Author

Great. Bundle of thanks to both of you for your precious feedback. I shall integrate all changes mentioned above and build the code as suggested before my next commit.

@code-with-abdullah
Copy link
Contributor Author

@diemol and @krmahadevan

Thanks for your input on the PR. All the changes you requested have been integrated. Please review and let me know if any further changes are required.

@BilalKamran
Copy link
Contributor

BilalKamran commented Mar 6, 2023

Seems one of the users in the commits has not signed the CLA, please check.

@diemol Resolved

@BilalKamran
Copy link
Contributor

@krmahadevan @diemol requested changes are done, pr please

@code-with-abdullah code-with-abdullah requested review from krmahadevan and diemol and removed request for diemol and krmahadevan March 7, 2023 10:25
Copy link
Contributor

@krmahadevan krmahadevan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diemol the changes look good to me. Please help take a look incase, I missed something.

@BilalKamran
Copy link
Contributor

@diemol please let us know if any change needed, we really hope to get this resolved and released with 4.9.

Copy link
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @code-with-abdullah!

Thanks for you help, @krmahadevan!

@diemol diemol merged commit 30ae31c into SeleniumHQ:trunk Mar 21, 2023
@code-with-abdullah
Copy link
Contributor Author

Thanks a lot @diemol
Stay blessed :)

@code-with-abdullah code-with-abdullah deleted the hotfix/11158 branch March 21, 2023 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants