Below are the imports I am using:
import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import util.WebConnector;
import java.io.IOException;
import java.net.MalformedURLException;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.fail;
Can you please send the entire code ....also the exact line where it is throwing this error.
[b:2bi1rh68]Please find below the full code:[/b:2bi1rh68]
The issue appears in the code which takes screenshots, if I comment out the below 2 lines I don't get the error.
final byte[] screenshot = ((TakesScreenshot) selenium.driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
package tests;
import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.sikuli.script.FindFailed;
import util.WebConnector;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.*;
import java.net.MalformedURLException;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.fail;
public class CommonUtil {
WebConnector selenium = WebConnector.getInstance();
Pages pages = new Pages();
private int assetCount = 0;
@Before
public void setUp() throws MalformedURLException {
selenium.openBrowser();
}
@After()
public void tearDown(Scenario scenario) throws InterruptedException, IOException {
if (scenario.isFailed()) {
scenario.write("Failed Scenario: " + scenario.getName());
// Take a screenshot
final byte[] screenshot = ((TakesScreenshot) selenium.driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
doLogOutAndQuit();
}
public static void assertForCondition(boolean condition) {
try {
assertTrue(condition);
} catch (Exception e) {
e.printStackTrace();
fail("Error occurred " + e.getMessage());
}
}
@After("@downloadasset")
public void deleteDownloadedAsset() throws InterruptedException, FindFailed, IOException {
pages.abstractPage().deleteDownloadedAssetFromDesktop();
}
public void doLogOutAndQuit() {
pages.abstractPage().navigateToQuickFindPage();
pages.quickFindPage().clickAdvancedLink();
pages.advancedPage().logOut();
assertForCondition(pages.logOutPage().isLogOutSuccessful());
selenium.quit();
}
public void navigateLoginAcceptTerms() throws FindFailed, InterruptedException {
pages.abstractPage().navigateToAssetBankPage();
pages.abstractPage().doLogin();
pages.termsAndConditionsPage().AcceptTermsAndConditions();
}
}
scenario.embed(screenshot, "image/png");
This line as the error
I am not sure what Scenario class does in your framework
But it looks like issue in scenario class
Can you contact the person who made this file - Scenario
scenario belongs to cucumber api
http://cucumber.github.io/api/cucumber/jvm/javadoc/cucumber/api/Scenario.html
I found the cause of it, driver.quit() throws this error, I am using driver.close() now and I don't get this issue.
I still don't understand why driver.quit() is causing this issue, it used to work fine until recently.
Not sure why you got the error in driver.quit(). Could you please explain a bit more.
As I didnt see this issue when I used your code.