-
Notifications
You must be signed in to change notification settings - Fork 45
Unwrap wrapped drivers #57
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
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 |
@@ -109,8 +109,8 @@ public BufferedImage takeScreenshot() { | |||
* @return BufferedImage resulting image | |||
*/ | |||
public BufferedImage takeScreenshotEntirePage() { | |||
if (driver instanceof EventFiringWebDriver) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
EventFiringWebDriver
also 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.WrapsDriver
should be replaced byorg.openqa.selenium.WrapsDriver
. (Should be available as of Selenium v3.14.0, see SeleniumHQ/selenium@3665dd7#diff-c68b4f7410690a3e2973585f06af6b92.)