0

When i use Ashot with selenium to capture screenshot for particular webelement,its not working.I have also attached the logs for reference.

Screenshot for taking full page is working.

Note : I have updated the latest jar's as mention in comment

Iam using Chrome Driver ,selenium 3.8.1 standalone jar, Ashot 1.5.2 jar.

 @Test

public void launchBrowser() 
{        

   System.setProperty("webdriver.chrome.driver","/Applications/webdriver/chromedriver");

driver = new ChromeDriver();

    }
@Test
public void openApplication() throws IOException, InterruptedException
{

driver.get("https://myurl");

driver.manage().window().maximize();

 WebDriverWait wait = new WebDriverWait(driver, 50);
  wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("commonuileftpanel")));
WebElement portal =driver.findElement(By.id("commonuileftpanel"));                                        
Screenshot myScreenshot = new AShot().takeScreenshot(driver,portal); 

BufferedImage original = myScreenshot.getImage();
BufferedImage expected = ImageIO.read(new File("/Applications/webdriver/results.png"));
ImageDiff diff = new ImageDiffer().makeDiff(original, expected);
BufferedImage difffullImage = diff.getMarkedImage();
File outputfile = new File("/Applications/webdriver/diffImage.png");
ImageIO.write(difffullImage, "PNG", outputfile);

Boolean diffval = diff.hasDiff();
Assert.assertFalse(diffval);

driver.quit();

}

@Test
public void closeDriver() 
{
if(driver!=null) 
{
driver.close();
}

Added screenshot :
enter image description here

Error Message :

Starting ChromeDriver 2.34.522932 (4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e) on port 3753
Only local connections are allowed.
Jan 12, 2018 4:02:52 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
ChromeDriver: chrome on MAC (d1a7d84c06ae31e76c872e6be1a61824)

PASSED: closeDriver
PASSED: launchBrowser
FAILED: openApplication
org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'offset' of null
  (Session info: chrome=63.0.3239.132)
  (Driver info: chromedriver=2.34.522932 (4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e),platform=Mac OS X 10.13.1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'test', ip: '', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.1', java.version: '1.8.0_152'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptSslCerts: true, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.34.522932 (4140ab217e1ca1..., userDataDir: /var/folders/j_/f03djz4n2bv...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 63.0.3239.132, webStorageEnabled: true}
Session ID: d1a7d84c06ae31e76c872e6be1a61824
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:537)
    at ru.yandex.qatools.ashot.util.JsCoords.findCoordsWithJquery(JsCoords.java:30)
    at ru.yandex.qatools.ashot.coordinates.JqueryCoordsProvider.ofElement(JqueryCoordsProvider.java:13)
    at ru.yandex.qatools.ashot.coordinates.CoordsProvider.ofElements(CoordsProvider.java:21)
    at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:115)
    at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:132)
    at ExampleSel3.screenshotParticularTag(ExampleSel3.java:187)
    at ExampleSel3.openApplication(ExampleSel3.java:96)
    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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:571)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:707)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:979)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1116)
    at org.testng.TestNG.runSuites(TestNG.java:1028)
    at org.testng.TestNG.run(TestNG.java:996)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
sasikumar
  • 567
  • 2
  • 8
  • 28

1 Answers1

0

The error says it all :

org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'offset' of null

It doesn't looks like your execution have reached till new AShot().takeScreenshot(driver,portal);

Your main issue is the version compatibility among the binaries you are using as follows :

  • You are using java.version: '1.8.0_77'
  • You are using chromedriver=2.34.522932
  • You are using chrome=63.0.3239.132
  • But you are using Selenium v2.52.0 of '2016-02-11 19:06:42'

Solution

  • Upgrade JDK to recent levels Version 8 Update 151.
  • Keep ChromeDriver to ChromeDriver v2.34 level.
  • Keep Chrome to Chrome v63.x level.
  • Upgrade Selenium to current levels Version 3.8.1.
  • Execute your Test.

For a detailed discussion on the error sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) you can see this Discussion

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for the comment . I tried as you said but same error , org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'offset' of null (Driver info: chromedriver=2.34.522932 (4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e),platform=Mac OS X 10.13.1 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z' System info: host: 'test', ip: '', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.1', java.version: '1.8.0_152' – sasikumar Jan 11 '18 at 10:18
  • 4 additional steps : 1) **`Clean`** the `Project` from your `IDE` and `Build` your project work space. 2) Run **`CCleaner`** tool to wipe away all the OS chores. 3) If your `Chrome` base version is too old, `uninstall` **Chrome** through **`Revo Uninstaller`** and install a recent GA version of `Chrome`. 4)Run your `Test`. – undetected Selenium Jan 11 '18 at 10:22
  • Please update the question with your complete Code block and the complete error stack trace. – undetected Selenium Jan 11 '18 at 10:24
  • I did everthing except 2) point, instead rebooted my machine. Again same Error. – sasikumar Jan 11 '18 at 11:14
  • All the Points #1, # 2 and #3 are crucial. Regular usage of point # 2 will give you relief for all the unwanted errors. Do it once and let me know the status. – undetected Selenium Jan 11 '18 at 11:16
  • Did everything still same issue ! – sasikumar Jan 12 '18 at 10:34
  • @sasikumar Can you update the question with the fresh set of logs to analyze what's wrong happening? – undetected Selenium Jan 12 '18 at 10:36
  • I still don't believe the error coming out of `aShot()`. Can you update the question with all the `@Test` annotations for `PASSED: closeDriver PASSED: launchBrowser and FAILED: openApplication` – undetected Selenium Jan 12 '18 at 11:30
  • any clues for the above! – sasikumar Jan 22 '18 at 11:12
  • I still don't think `(By.id("commonuileftpanel"))` is getting resolved. Can you share the relevant `HTML`? – undetected Selenium Jan 22 '18 at 11:23
  • I have already added the screenshot ! you want me to add more HTML – sasikumar Jan 22 '18 at 11:26