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

Screenshots not working with RemoteWebDriver and Shutterbug 1.6 #103

Closed
therealdjryan opened this issue Mar 24, 2022 · 7 comments
Closed
Assignees

Comments

@therealdjryan
Copy link

This bug still seems to be present. I am running selenium grid 4.1.2 and shutterbug 1.6

java.lang.IllegalArgumentException: object is not an instance of declaring class
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.assertthat.selenium_shutterbug.utils.web.Browser.defineCustomCommand(Browser.java:918)
	at com.assertthat.selenium_shutterbug.utils.web.Browser.takeFullPageScreenshotChromeCommand(Browser.java:713)
	at com.assertthat.selenium_shutterbug.utils.web.Browser.takeFullPageScreenshot(Browser.java:155)
	at com.assertthat.selenium_shutterbug.core.Shutterbug.shootPage(Shutterbug.java:154)
	at com.assertthat.selenium_shutterbug.core.Shutterbug.shootPage(Shutterbug.java:83)
	at com.assertthat.selenium_shutterbug.core.Shutterbug.shootPage(Shutterbug.java:69)
@glibas glibas self-assigned this Mar 25, 2022
@glibas
Copy link
Member

glibas commented Mar 25, 2022

Hi @therealdjryan cannot reproduce it here. Could you please share example project/code

@therealdjryan
Copy link
Author

@glibas
Copy link
Member

glibas commented Mar 26, 2022

Hi @therealdjryan ,
It works fine with declaring WebDriver as

WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), new ChromeOptions());

It does not work with declaring through builder as in your example

WebDriver driver = RemoteWebDriver.builder().address("http://127.0.0.1:4444") .addAlternative(new ChromeOptions()).build();

The reason for that is that CommandExecutor is instantiated by a lambda result in RemoteWebDriverBuilder

CommandExecutor executor = (CommandExecutor)result.map((res) -> { return this.createExecutor(handler, res); });
Will have a look how we can workaround that. In the meantime you can avoid using RemoteWebDriverBuilder which is still marked as Beta.

@therealdjryan
Copy link
Author

Hi @glibas, Thanks for chasing down the workaround. Unfortunately in my environment I need to be able to set the readTimeout to handle a couple sluggish pages. I don't think there's a way to do that without using the builder, or rather using ClientConfig which is set in the builder

@glibas
Copy link
Member

glibas commented Mar 31, 2022

Hi @therealdjryan ,
Still looking how to make it work with builder. There are some issues with invoking method using reflection on lambda refs as mentioned above.

There is a way, however to set your readTimeout without using builder. It's not pretty but works (effectively same what RemoteWebdriver does under the hood but with Custom ClientConfig instead of default one)

URL remoteAddress = new URL("http://localhost:4444/wd/hub");
Tracer tracer = OpenTelemetryTracer.getInstance();
ClientConfig config = ClientConfig.defaultConfig().baseUrl(remoteAddress).readTimeout(Duration.ofSeconds(60));
CommandExecutor executor = new HttpCommandExecutor(Collections.emptyMap(), config, new TracedHttpClient.Factory(tracer, org.openqa.selenium.remote.http.HttpClient.Factory.createDefault()));
CommandExecutor executorTraced =  new TracedCommandExecutor(executor, tracer);
WebDriver webDriver = new RemoteWebDriver(executorTraced, new ChromeOptions());

@therealdjryan
Copy link
Author

@glibas,
I am perfectly happy with this solution, it works great. Could you update the readme so future generations know the limitation/solution

Thanks!
Dennis

@glibas
Copy link
Member

glibas commented Mar 31, 2022

Hi @therealdjryan ,
Will add this to Readme unless I can marry it up with the builder.
Thanks for raising!
Glib

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

No branches or pull requests

2 participants