MicroFocus / leanft-selenium-java-sdk

LeanFT Java SDK for Selenium - LeanFT for Selenium Java SDK extends the Selenium WebDriver API with locators and utilities that enable creating tests which are more robust, and reduces Selenium test automation and maintenance efforts.
Apache License 2.0
11 stars 4 forks source link

Utils.snapshot fails with an error if the webelement is not fully visible in the browser #3

Open panama69 opened 6 years ago

panama69 commented 6 years ago

The below error happens when the web element you wish to take a snapshot of is not fully visible with in the browser. This became apparent when replaying the test on different machines where the browsers didn't open to the size where the script was originally created.

Suggestion would be for the Utils.snapshot to bring the object into the visible area of the browser before attempting to take the snapshot.

As a short term workaround, I now perform a Utils.highlight so the object is moved in to the visible area of the browser before performing Utils.snapshot.

Utils.scrollIntoView did not seem to work.

Run Error - Custom Step

java.awt.image.RasterFormatException: (y + height) is outside of Raster at sun.awt.image.ByteInterleavedRaster.createWritableChild(ByteInterleavedRaster.java:1248) at java.awt.image.BufferedImage.getSubimage(BufferedImage.java:1202) at com.hpe.leanft.selenium.Utils.getSnapshot(Utils.java:77) at net.mf.SeleniumTest.test(SeleniumTest.java:110) 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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) 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 org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Description Error in script executionCheck the error thrown Execution Time 2018-08-17 19:31:49 Duration 00:00:00.000

panama69 commented 6 years ago

After reviewing the formula in the InternalUtils.isVisible and still scratching my head as to why the calculations seem to be correct but I get the above error, it dawned on me this doesn't take in to account the size of the Chrome info bar:

"Chrome is being controlled by automated test software."

If I disable the infobar using:

ChromeOptions options = new ChromeOptions(); 
options.addArguments("disable-infobars"); 
WebDriver driver = new ChromeDriver(options);

Should the Utils account for the info bars or should the above note be added to the documentation?