Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
getting below while running test case in selenium webdriver.

java.lang.RuntimeException: java.lang.NullPointerException
	at ru.yandex.qatools.ashot.util.InnerScript.execute(InnerScript.java:29)
	at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getFullHeight(ViewportPastingDecorator.java:67)
	at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getScreenshot(ViewportPastingDecorator.java:41)
	at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getScreenshot(ViewportPastingDecorator.java:35)
	at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:143)
	at selenium.org.sample.SampleProject.Screenshot.ScreenshotPage.ScreenshotPage1(ScreenshotPage.java:14)



below is my class to of screenshot
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;
import selenium.org.sample.SampleProject.TestBase.TestBase;

public class ScreenshotPage extends TestBase
{
	 public void ScreenshotPage1() throws InterruptedException, IOException
	{ 
		Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
	    ImageIO.write(fpScreenshot.getImage(),"PNG",new File("D:/selenium/"+System.currentTimeMillis()+".png"));
	 }
}


and below I am calling method of screenshotPage class.

import java.io.IOException;
import org.openqa.selenium.support.PageFactory;
import org.testng.Assert;
import org.testng.annotations.Test;
import selenium.org.sample.SampleProject.UIAction.SignIn;
import selenium.org.sample.SampleProject.ExcelReader.ExcelReader;
import selenium.org.sample.SampleProject.Screenshot.ScreenshotPage;

public class AppTest extends ExcelReader
{
	@Test(dataProvider="testdata")
	public void Log(String email,String pwd) throws IOException, InterruptedException
	{
		ScreenshotPage S=new ScreenshotPage();
		System.out.println("Sign in page");
		SignIn loginpage = PageFactory.initElements(driver, SignIn.class);
		 loginpage.setUserName(email); // Enter username
		 loginpage.setPwd(pwd); // Enter password
		 Thread.sleep(8000);
		 S.ScreenshotPage1();//calling method from ScreenshotPage class 
		 loginpage.Sign_In_btn();// Submit button click
		 driver.manage().window().maximize();
		 try
		 {
		Assert.assertEquals(driver.getTitle(),"My account - My Store");
	     System.out.println("Log  IN successfull1");
		 }
		 catch(AssertionError E)
		 {
			 System.out.println("Log  IN un-successfull"+E);
		 }
		 Thread.sleep(8000);
		S.ScreenshotPage1();	 
	} 


What I have tried:

below code is running successfully facing this issue only when calling method.

import java.io.IOException;
import org.openqa.selenium.support.PageFactory;
import org.testng.Assert;
import org.testng.annotations.Test;
import selenium.org.sample.SampleProject.UIAction.SignIn;
import selenium.org.sample.SampleProject.ExcelReader.ExcelReader;
import selenium.org.sample.SampleProject.Screenshot.ScreenshotPage;

public class AppTest extends ExcelReader
{
	@Test(dataProvider="testdata")
	public void Log(String email,String pwd) throws IOException, InterruptedException
	{
		ScreenshotPage S=new ScreenshotPage();
		System.out.println("Sign in page");
		SignIn loginpage = PageFactory.initElements(driver, SignIn.class);
		 loginpage.setUserName(email);// Enter username
		 loginpage.setPwd(pwd);// enter password
		 Thread.sleep(8000);
		Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
	     ImageIO.write(fpScreenshot.getImage(),"PNG",new File("D:/selenium/"+System.currentTimeMillis()+".png"));

		loginpage.Sign_In_btn();// clicks button
		 driver.manage().window().maximize();
		 try
		 {
		Assert.assertEquals(driver.getTitle(),"My account - My Store");
	     System.out.println("Log  IN successfull1");
	
		 }
		 catch(AssertionError E)
		 {
			 System.out.println("Log  IN un-successfull"+E);
		 }
		 Thread.sleep(8000);
		S.ScreenshotPage1();
	} 
Posted
Comments
Richard MacCutchan 16-Jul-18 1:25am    
The error message clearly states that the error occurs on line 29 of Innerscript.java. Where is that code?
Jochen Arndt 16-Jul-18 9:42am    
The variable driver is nowhere defined and initialised in your code.
swati gapat 16-Jul-18 11:25am    
It is in TestBase and Screenshot Page extends TestBase.
Jochen Arndt 16-Jul-18 12:41pm    
And is it properly initialised there?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900