Unable to take screen shot of every step | Selenium Forum
M
Posted on 22/10/2016
Hi ,

i am unable to take screen shot of every step in the extent report

screen is coming with the crop PFA screen shot. below are my code

Having said that i have gone through all the video
2- i tried my all possible scenario

Please reply with solution

package pagefactory;

import java.util.Date;

import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import com.factory.util.Utility;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

import pagefactory.constans.NaukriConstants;
import pagefactorybase.basePage.Page;

public class LoginPage extends Page {


@FindBy(xpath=NaukriConstants.LOGIN_LINK)
public WebElement login;


@FindBy(xpath=NaukriConstants.USER_NAME)
public WebElement user;

//@FindBy(xpath="//*[@id='userRad']")
//public WebElement radio;


@FindBy(xpath=NaukriConstants.EMAIL_FIELD)
public WebElement email;


@FindBy(xpath=NaukriConstants.PASSWORD_FIELD)
public WebElement pass;
//public ExtentTest extent ;


public LoginPage(WebDriver driver ,ExtentTest test)
{
super(driver,test);

}
public Object dologin(String username ,String password)
{
//Date d=new Date();
//String screenshotFile=d.toString().replace(":", "_").replace(" ", "_")+".png";

test.log(LogStatus.INFO, "Clicking in the login link ");
login.click();

test.log(LogStatus.INFO, "opening the loginlightbox");
user.click();
//test.log(LogStatus.INFO,"Screenshot-> "+test.addScreenCapture(System.getProperty("user.dir")+"//screenshots//"+screenshotFile));
test.log(LogStatus.INFO,"Screenshot-> "+test.addScreenCapture("E:\\Reports\\openBrowser.png"));
//radio.click();
test.log(LogStatus.INFO, "Entering username and password "+username+" /"+password);
//test.log(LogStatus.INFO,"Screenshot-> "+test.addScreenCapture(System.getProperty("user.dir")+"//screenshots//"+screenshotFile));
test.log(LogStatus.INFO,"Screenshot-> "+test.addScreenCapture("E:\\Reports\\openBrowser.png"));
email.sendKeys(username);
//test.log(LogStatus.INFO,"Screenshot-> "+test.addScreenCapture(System.getProperty("user.dir")+"//screenshots//"+screenshotFile));
test.log(LogStatus.INFO,"Screenshot-> "+test.addScreenCapture("E:\\Reports\\openBrowser.png"));
pass.sendKeys(password);
//test.log(LogStatus.INFO,"Screenshot-> "+test.addScreenCapture(System.getProperty("user.dir")+"//screenshots//"+screenshotFile));

pass.sendKeys(Keys.ENTER);

boolean loginsuccess=true;
if(loginsuccess){

test.log(LogStatus.INFO, "Login Success");
LandingPage landingpage= new LandingPage(driver,test);
PageFactory.initElements(driver, landingpage);
return landingpage;
}
else
{

test.log(LogStatus.INFO, "Login not Success");

LoginPage loginpage= new LoginPage(driver,test);
PageFactory.initElements(driver, loginpage);
loginpage.takeScreenShot(driver);
return loginpage;
}
}}

---------------------------------------------
Screen shot method in page calss----------


public void takeScreenShot(WebDriver driver ){
// fileName of the screenshot
Date d=new Date();
String screenshotFile=d.toString().replace(":", "_").replace(" ", "_")+".png";
// store screenshot in that file
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir")+"//screenshots//"+screenshotFile));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//put screenshot file in reports
test.log(LogStatus.INFO,"Screenshot-> "+test.addScreenCapture(System.getProperty("user.dir")+"//screenshots//"+screenshotFile));
//test.l
// test.log(LogStatus.INFO,"Screenshot-> "+test.addScreenCapture(System.getProperty("user.dir")+"//screenshots//"+screenshotFile));

}


As i can call this method---takeScreenShot() with the step so i am using
test.log(LogStatus.INFO,"Screenshot-> "+test.addScreenCapture(System.getProperty("user.dir")+"//screenshots//"+screenshotFile));

if i am wrong pls correct where i need to update the code


Thanks
deepak

M
Replied on 24/10/2016

you'll have to name every screen shot you take a different name.

for ex. screenshot1.png, screenshot2.png, screenshot3.png, screenshot4.png etc.


M
Replied on 24/10/2016

ok.. I have tired this as well but did not work
can you tell me where I have to update in the code
please update on the code
and give with one example I mean call this method after given name of the screen shot so that I can easily understand where I did the mistake


M
Replied on 25/10/2016

hi ,

pls reply


M
Replied on 25/10/2016

are you putting a date suffix in the name of the screenshot? put time suffix also.


M
Replied on 25/10/2016

No I am not doing this plz can you tell me where I have to change in my code
I have posted both the code
screen shot ---method

2-testcase as well

so plz look into my both the code and reply accordingly


M
Replied on 26/10/2016

i cannot help you here when can you come to skype/team viewer?


M
Replied on 26/10/2016

i can online at 9 pm on Skype


M
Replied on 01/11/2016

hi,

can you come at 7pm IST.


M
Replied on 15/11/2016

Hi ,

now I am facing 3 issue


1-same screen shot Multilpe time
2-Unable to execute project with

public Page(WebDriver driver, ExtentTest test) {
this.driver = driver;
this.test = test;
menu = PageFactory.initElements(driver, TopMenu.class);
takeScreenShot(driver);
}


Error---

2016.11.16.09.50.37.5037.png
2016.11.16.09.50.48.5048.png
2016.11.16.09.51.01.511.png
FAILED: selectmessgae
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.openqa.selenium.support.PageFactory.instantiatePage(PageFactory.java:138)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:64)
at pagefactorybase.basePage.Page.<init>(Page.java:33)
at pagefactory.Launch.<init>(Launch.java:26)
at testcases.LandingTest.selectmessgae(LandingTest.java:131)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

Solution-- able to execute after comment below line
public Page(WebDriver driver, ExtentTest test) {
this.driver = driver;
this.test = test;
//menu = PageFactory.initElements(driver, TopMenu.class);
takeScreenShot(driver);
}


3-Screen shot not coming next to the Action line


M
Replied on 16/11/2016

Hi vaibhav,

Thanks for resolved this issue.