Unwrap wrapped drivers#57
Conversation
|
Hi @beatngu13 , Thank you for your contribution. Need to think how we can support both versions of the WrapsDriver. Will take a look tonight |
| * @return BufferedImage resulting image | ||
| */ | ||
| public BufferedImage takeScreenshotEntirePage() { | ||
| if (driver instanceof EventFiringWebDriver) { |
There was a problem hiding this comment.
I would suggest adding something like
private WebDriver unwrapDriver(String name){
try {
if(Class.forName(name).isInstance(driver)){
return ((WrapsDriver) driver).getWrappedDriver();
}
} catch (ClassNotFoundException e) {
;
}
return driver;
}
So that then in takeScreeshotEntirePage() we can be backward compatible with earlier selenium versions e.g.
driver = unwrapDriver("org.openqa.selenium.WrapsDriver");
driver = unwrapDriver("org.openqa.selenium.internal.WrapsDriver");
There was a problem hiding this comment.
Since you have bumped the Selenium version in the meantime, I would rather rebase my branch and switch to org.openqa.selenium.WrapsDriver, which is implemented by org.openqa.selenium.internal.WrapsDriver, so this would support both. (See subinterfaces: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WrapsDriver.html).
`EventFiringWebDriver` also implements `WrapsDriver`, which is more general and should be implemented by all wrappers.
|
Selenium dependency is only in compile scope so it won't be included in the distribution library. We still need to check for both versions of the WrapsDriver as if someone is using shutterbug with selenium version prior to 3.14.0 they'll get runtime error. |
|
Isn't this the default scope anyway? However, it's your lib; if you want me to go down the path of reflection, I'll do. 😉 |
|
Added a new commit that unwraps via reflection. Feel free to delete it if you want to stick to the new |
Suggestion via #57 (comment).
EventFiringWebDriveralso implementsWrapsDriver, which is more general and should be implemented by all wrappers. This recently cause issues at retest/recheck-web#277.As soon as Selenium is updated,
org.openqa.selenium.internal.WrapsDrivershould be replaced byorg.openqa.selenium.WrapsDriver. (Should be available as of Selenium v3.14.0, see SeleniumHQ/selenium@3665dd7#diff-c68b4f7410690a3e2973585f06af6b92.)