Selenium-cucumber frameork error while taking screenshot

0

I am executing a selenium-cucumber framework and I am having the following issue:`

org.openqa.selenium.WebDriverException: Could not convert screenshot to base64 - 
Error: Unable to load canvas into base64 string - 
[Exception... "Failure"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  
location: "JS frame :: file:///C:/Users/c38151/AppData/Local/Temp/anonymous7393315997897601641webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js :: fxdriver.screenshot.toBase64 :: line 10440"  data: no]
Command duration or timeout: 1.13 seconds
Build info: version: '2.53.0', 
revision: '35ae25b1534ae328c771e0856c93e187490ca824', 
time: '2016-03-15 10:43:46'
System info: host: 'W7E1384109', ip: '172.26.31.114', 
os.name: 'Windows 7', 
os.arch: 'amd64', 
os.version: '6.1', 
java.version: '1.8.0_74'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=45.2.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: e48040a1-37c2-4767-a46f-acaf697dc8c4

Please let me know the soulution of this.Is this related to lo RAM?

selenium-webdriver
automation
cucumber
asked on Stack Overflow Jun 11, 2017 by Bitz • edited Aug 8, 2017 by Ashish Deshmukh

3 Answers

0
@After public void snapShotOnFail(Scenario scenario) throws Throwable {
        try {
            if (scenario.isFailed()) {
                final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
                scenario.embed(screenshot, "image/png");

            }
        } catch (WebDriverException somePlatformsDontSupportScreenshots) {
            System.err.println(somePlatformsDontSupportScreenshots.getMessage());
        }
    }
answered on Stack Overflow May 29, 2018 by snikt
0

try this and modify it as per your needs

    @After
public void shutDown(Scenario scenario){
    if (scenario.isFailed()) {
        final byte[] screenshot = ((TakesScreenshot) Driver.getDriver()).getScreenshotAs(OutputType.BYTES);
        scenario.embed(screenshot, "image/png");
    }
    Driver.closeDriver();

}

answered on Stack Overflow May 29, 2018 by mbn217
0

Try this one to error while taking screenshot.. And it could add screenshots of a failed test case in Cucumber extent report.

public void forAfterScen(Scenario scenario) throws IOException
    {
        if (scenario.isFailed()) {
            String screenshotName = scenario.getName().replaceAll(" ", "_");
            try {
                TakesScreenshot ts = (TakesScreenshot) driver;
                File sourcePath = ts.getScreenshotAs(OutputType.FILE);

                File destinationPath = new File(System.getProperty("user.dir") + "\\Report\\" + screenshotName+".png");

                Files.copy(sourcePath, destinationPath);   

                Reporter.addScreenCaptureFromPath(destinationPath.toString());
                Reporter.addScenarioLog(screenshotName);
            } catch (IOException e) {
            } 
        }
    }
answered on Stack Overflow Dec 21, 2018 by Sandeep K

User contributions licensed under CC BY-SA 3.0