本文整理匯總了Java中cucumber.api.Scenario.isFailed方法的典型用法代碼示例。如果您正苦於以下問題:Java Scenario.isFailed方法的具體用法?Java Scenario.isFailed怎麽用?Java Scenario.isFailed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cucumber.api.Scenario
的用法示例。
在下文中一共展示了Scenario.isFailed方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: embedScreenshot
import cucumber.api.Scenario; //導入方法依賴的package包/類
@After
public void embedScreenshot(Scenario scenario) {
try {
if (!scenario.isFailed()) {
// Take a screenshot only in the failure case
return;
}
String webDriverType = System.getProperty("WebDriverType");
if (!webDriverType.equals("HtmlUnit")) {
// HtmlUnit does not support screenshots
byte[] screenshot = getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
} catch (WebDriverException somePlatformsDontSupportScreenshots) {
scenario.write(somePlatformsDontSupportScreenshots.getMessage());
}
}
示例2: afterTest
import cucumber.api.Scenario; //導入方法依賴的package包/類
/**
* <p>
* Takes screen-shot if the scenario fails
* </p>
*
* @param scenario will be the individual scenario's within the Feature files
* @throws InterruptedException Exception thrown if there is an interuption within the JVM
*/
@After()
public void afterTest(Scenario scenario) throws InterruptedException {
LOG.info("Taking screenshot IF Test Failed");
System.out.println("Taking screenshot IF Test Failed (sysOut)");
if (scenario.isFailed()) {
try {
System.out.println("Scenario FAILED... screen shot taken");
scenario.write(getDriver().getCurrentUrl());
byte[] screenShot = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenShot, "image/png");
} catch (WebDriverException e) {
LOG.error(e.getMessage());
}
}
}
示例3: tearDownDriver
import cucumber.api.Scenario; //導入方法依賴的package包/類
public void tearDownDriver(Scenario scenario) throws Exception {
try {
if (ObjectRepo.driver != null) {
if(scenario.isFailed())
scenario.write(new GenericHelper(ObjectRepo.driver).takeScreenShot(scenario.getName()));
ObjectRepo.driver.quit();
ObjectRepo.reader = null;
ObjectRepo.driver = null;
oLog.info("Shutting Down the driver");
}
} catch (Exception e) {
oLog.error(e);
throw e;
}
}
示例4: handleError
import cucumber.api.Scenario; //導入方法依賴的package包/類
public static void handleError(String url, String login, String password, Scenario scenario) throws Exception {
String issueId = "";
for(String tag : scenario.getSourceTagNames()) {
if (tag.contains("SAM-")) {
issueId = tag.substring(1);
break;
}
}
if (issueId.equals("")) {
return;
}
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(login, password);
provider.setCredentials(AuthScope.ANY, credentials);
HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
URI uri = UriBuilder.fromUri(url)
.path("/rest/api/2/issue/" + issueId).build();
String status = "Passed";
if (scenario != null && scenario.isFailed()) {
status = "Failed";
}
HttpPut request = new HttpPut(uri);
HttpEntity entity = new StringEntity("{\"fields\":{\"customfield_10007\": \"" + status + "\"}}");
request.setEntity(entity);
request.addHeader("Content-Type", "application/json");
HttpResponse response = client.execute(request);
client.getConnectionManager().shutdown();
}
示例5: tearDown
import cucumber.api.Scenario; //導入方法依賴的package包/類
@After
public void tearDown(Scenario scenario) {
if (scenario.isFailed()) {
try {
logger.info("Test failed, taking screenshot");
byte[] screenshot = ((TakesScreenshot) new Augmenter().augment(getAppiumDriver()))
.getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
catch (WebDriverException wde) {
System.err.println(wde.getMessage());
}
catch (ClassCastException cce) {
cce.printStackTrace();
}
}
application.tearDown();
}
示例6: afterScenario
import cucumber.api.Scenario; //導入方法依賴的package包/類
@After
public void afterScenario( Scenario scenario ) throws Exception
{
try
{
attachLog();
if( scenario.isFailed() )
{
try
{
scenario.write( "Current Page URL is " + getDriver().getCurrentUrl() );
byte[] screenshot;
try
{
screenshot = ( ( TakesScreenshot ) getDriver() ).getScreenshotAs( OutputType.BYTES );
} catch( ClassCastException weNeedToAugmentOurDriverObject )
{
screenshot = ( ( TakesScreenshot ) new Augmenter().augment( getDriver() ) ).getScreenshotAs( OutputType.BYTES );
}
String relativeScrnShotPath = takeScreenshot().substring(takeScreenshot().indexOf("screenshots"));
Reporter.addScreenCaptureFromPath(relativeScrnShotPath, getDriver().getCurrentUrl());
} catch( WebDriverException somePlatformsDontSupportScreenshots )
{
System.err.println( somePlatformsDontSupportScreenshots.getMessage() );
}
}
} finally
{
closeDriverObjects();
}
}
示例7: outputFinalScreenshot
import cucumber.api.Scenario; //導入方法依賴的package包/類
/**
* Output a screenshot of the final web page reached in this test scenario, useful for investigating test
* failures and as a record of what exactly was tested. The output gets picked up by the Cucumber reports and
* plugins.
* <p>Uses the <i>takeScreenshots</i> configuration setting.</p>
* @param scenario The scenario just completed
*/
private void outputFinalScreenshot(Scenario scenario) {
String takeScreenshots = env.getRequiredProperty("takeScreenshots");
switch (takeScreenshots) {
case "onErrorOnly":
if (scenario.isFailed()) {
takeScreenshot(scenario);
}
break;
case "always":
takeScreenshot(scenario);
break;
case "never":
break;
default:
String message = "Unknown takeScreenshots setting: " + takeScreenshots;
logger.error(message);
throw new IllegalArgumentException(message);
}
}
示例8: outputFinalHtml
import cucumber.api.Scenario; //導入方法依賴的package包/類
/**
* Output the raw HTML of the final web page reached in this test scenario, useful for investigating test
* failures and as a record of what exactly was tested. The files are output to the same directory as the reports.
* <p>Uses the <i>outputHtml</i> configuration setting.</p>
* @param scenario The scenario just completed
*/
private void outputFinalHtml(Scenario scenario) {
String outputHtml = env.getRequiredProperty("outputHtml");
switch (outputHtml) {
case "onErrorOnly":
if (scenario.isFailed()) {
writeHtml(scenario);
}
break;
case "always":
writeHtml(scenario);
break;
case "never":
break;
default:
String message = "Unknown outputHtml setting: " + outputHtml;
logger.error(message);
throw new IllegalArgumentException(message);
}
}
示例9: after
import cucumber.api.Scenario; //導入方法依賴的package包/類
public void after(Scenario scenario)
{
if (driverProvider.get() == null) {
LOG.warn("Driver for scenario {} {} is not running!", scenario.getId(), scenario.getName());
return;
}
if (scenario.isFailed()) {
StringBuilder sbPath = new StringBuilder();
sbPath.append(System.getProperty("user.dir")).append(File.separator).append("target").append(File.separator).append("seauto").append(File.separator).append("screenshots").append(File.separator).append(String.format("%s.png", scenario.getId().replaceAll(";", "__")));
LOG.debug("Save screenshot to {}", sbPath.toString());
driverProvider.saveScreenshotAs(sbPath.toString());
}
driverProvider.end();
}
示例10: afterClass
import cucumber.api.Scenario; //導入方法依賴的package包/類
@After
public void afterClass(Scenario scenario) throws InterruptedException, IOException {
if (scenario.isFailed()) {
try {
byte[] screenshot =
((TakesScreenshot) AppiumDriverManager.getDriver())
.getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
} catch (WebDriverException wde) {
System.err.println(wde.getMessage());
} catch (ClassCastException cce) {
cce.printStackTrace();
}
System.out.println("Inside After" + Thread.currentThread().getId());
}
AppiumDriverManager.getDriver().quit();
}
示例11: takeScreenshot
import cucumber.api.Scenario; //導入方法依賴的package包/類
@After
public void takeScreenshot(final Scenario scenario) {
if (scenario.isFailed() && webDriver instanceof TakesScreenshot) {
final String scenarioName = scenario.getName();
takeScreenshot(scenarioName, (TakesScreenshot) webDriver);
}
}
示例12: afterScenario
import cucumber.api.Scenario; //導入方法依賴的package包/類
/**
* Capture a selenium screenshot when a test fails and add it to the Cucumber generated report
* if the scenario has accessed selenium in its lifetime
* @throws InterruptedException
*/
@After
public void afterScenario(Scenario scenario) throws InterruptedException {
log.debug("Scenarion finished");
ScenarioGlobals scenarioGlobals = getCucumberManager().getCurrentScenarioGlobals();
TestEnvironment testNev = getSeleniumManager().getAssociatedTestEnvironment();
if (testNev != null && scenarioGlobals != null) {
boolean scenarioUsedSelenium = testNev.isWebDriverAccessedSince(scenarioGlobals.getScenarioStart());
if (scenarioUsedSelenium) {
if (scenario.isFailed()) {
log.debug("Scenarion failed while using selenium, so capture screenshot");
TakesScreenshot seleniumDriver = (TakesScreenshot) SenBotContext.getSeleniumDriver();
byte[] screenshotAs = seleniumDriver.getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshotAs, "image/png");
}
}
}
getCucumberManager().stopNewScenario();
}
示例13: tearDown
import cucumber.api.Scenario; //導入方法依賴的package包/類
@After
public void tearDown(Scenario scenario) {
try {
if (scenario.isFailed()) {
final byte[] screenshot = appiumDriver
.getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
appiumDriver.quit();
appiumService.stop();
} catch (Exception e) {
System.out.println("Exception while running Tear down :" + e.getMessage());
}
}
示例14: takeScreenshot
import cucumber.api.Scenario; //導入方法依賴的package包/類
/**
* Если сценарий завершился со статусом "fail" будет создан скриншот и сохранен в директорию
* {@code <project>/build/reports/tests}
*
* @param scenario текущий сценарий
*/
@After(order = 20)
public void takeScreenshot(Scenario scenario) {
if (scenario.isFailed()) {
AkitaScenario.sleep(1);
final byte[] screenshot = ((TakesScreenshot) getWebDriver()).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
}
示例15: after
import cucumber.api.Scenario; //導入方法依賴的package包/類
@After
public void after(Scenario scenario) {
if (scenario.isFailed()) {
Driver.embedScreenshot();
}
}