當前位置: 首頁>>代碼示例>>Java>>正文


Java Scenario類代碼示例

本文整理匯總了Java中cucumber.api.Scenario的典型用法代碼示例。如果您正苦於以下問題:Java Scenario類的具體用法?Java Scenario怎麽用?Java Scenario使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Scenario類屬於cucumber.api包,在下文中一共展示了Scenario類的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());
  }
}
 
開發者ID:robinsteel,項目名稱:Sqawsh,代碼行數:19,代碼來源:SharedDriver.java

示例2: teardown

import cucumber.api.Scenario; //導入依賴的package包/類
/**
 * Runs after every Cucumber test scenario.
 * @param scenario      The test scenario that has run
 */
@After
public void teardown(Scenario scenario) {
    logger.debug("After cucumber scenario: ********** {} **********", scenario.getName());

    // add to the test report
    outputDataUse(scenario);
    outputFinalScreenshot(scenario);
    outputFinalHtml(scenario);

    // log the current user out, if they are logged in
    if (driverWrapper.hasLink("Sign out")) {
        logger.debug("Logging the current user out...");
        driverWrapper.clickLink("Sign out");
    }

    // test cleanup (note: this will clear permanent cookies but not HTTP/Session cookies)
    driverWrapper.reset();
}
 
開發者ID:dvsa,項目名稱:mot-automated-testsuite,代碼行數:23,代碼來源:LifecycleHooks.java

示例3: 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());
        }
    }
}
 
開發者ID:usman-h,項目名稱:Habanero,代碼行數:24,代碼來源:ScreenShotHook.java

示例4: 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;
	}
}
 
開發者ID:rahulrathore44,項目名稱:SeleniumCucumber,代碼行數:19,代碼來源:InitializeWebDrive.java

示例5: 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();
}
 
開發者ID:mkolisnyk,項目名稱:0686OS,代碼行數:30,代碼來源:JiraUtils.java

示例6: 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();
}
 
開發者ID:HotwireDotCom,項目名稱:bdd-test-automation-for-mobile,代碼行數:19,代碼來源:SetupTeardownSteps.java

示例7: updateTestDetails

import cucumber.api.Scenario; //導入依賴的package包/類
/**
 * This method captures the GroupName, TestID and TestDescription details of each testcase under execution
 * @param scenario
 */
private void updateTestDetails(Scenario scenario){
	String featureScenario = scenario.getName();
	for(String tag : scenario.getSourceTagNames()){
		groupName = groupName + " " + tag.substring(0);
           System.out.println("Tag: " + tag);
       }
	if (featureScenario.contains("<") && featureScenario.contains(">")){
		this.testID = featureScenario.substring(
				featureScenario.indexOf("<") + 1,
				featureScenario.indexOf(">"));
		this.testDescription = featureScenario.substring(0, featureScenario.indexOf("<"));//starting from index 1 to skip @ sign of tags
	}

	System.out.println("Complete Scenario is :-" +featureScenario);
	System.out.println("Test Description is:- "+ this.testDescription);
	System.out.println("Group Name is:- "+ this.groupName);
	
	System.out.println("============================================================================================");
}
 
開發者ID:MastekLtd,項目名稱:SwiftLite,代碼行數:24,代碼來源:StepDefinitions.java

示例8: 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();
    }
}
 
開發者ID:hemano,項目名稱:cucumber-framework-java,代碼行數:33,代碼來源:StartingSteps.java

示例9: setUpScenario

import cucumber.api.Scenario; //導入依賴的package包/類
@Before()
public static void setUpScenario(Scenario scenario) throws TechnicalException {
    logger.debug("setUpScenario {} scenario.", scenario.getName());

    if (Context.getCurrentScenarioData() == 0) {
        // Retrieve Excel filename to read
        String scenarioName = System.getProperty("excelfilename") != null ? System.getProperty("excelfilename") : getFirstNonEnvironmentTag(scenario.getSourceTagNames());

        Context.setScenarioName(scenarioName);

        Context.getDataInputProvider().prepare(Context.getScenarioName());
        Context.getDataOutputProvider().prepare(Context.getScenarioName());
        Context.startCurrentScenario();
    }

    // Increment current Excel file line to read
    Context.goToNextData();
    Context.emptyScenarioRegistry();
    Context.saveValue(Constants.IS_CONNECTED_REGISTRY_KEY, String.valueOf(Auth.isConnected()));

    Context.setCurrentScenario(scenario);
    new Result.Success<>(Context.getScenarioName(), Messages.getMessage(SUCCESS_MESSAGE_BY_DEFAULT));

}
 
開發者ID:NoraUi,項目名稱:NoraUi,代碼行數:25,代碼來源:CucumberHooks.java

示例10: printProgressBuild

import cucumber.api.Scenario; //導入依賴的package包/類
private static void printProgressBuild(Scenario scenario) {
    int remainingTime = getRemainingTime();
    StringBuilder star = new StringBuilder();
    StringBuilder postStar = new StringBuilder();
    int width = scenario.getSourceTagNames().toString().length() + String.valueOf(Context.getCurrentScenarioData()).length()
            + String.valueOf(Context.getDataInputProvider().getNbGherkinExample()).length() + String.valueOf(Context.getNbFailure()).length() + String.valueOf(Context.getNbWarning()).length()
            + String.valueOf(remainingTime).length();

    String message = Messages.getMessage(PROGRESS_MESSAGE);
    for (int i = 0; i < message.length() - 12 + width; i++) {
        star.append("*");
    }
    postStar.append("*");
    for (int i = 0; i < message.length() - 14 + width; i++) {
        postStar.append(" ");
    }
    postStar.append("*");

    logger.info("{}", star);
    logger.info("{}", postStar);
    logger.info(message, scenario.getSourceTagNames(), Context.getCurrentScenarioData(), Context.getDataInputProvider().getNbGherkinExample(), Context.getNbFailure(), Context.getNbWarning(),
            remainingTime);
    logger.info("{}", postStar);
    logger.info("{}", star);
}
 
開發者ID:NoraUi,項目名稱:NoraUi,代碼行數:26,代碼來源:CucumberHooks.java

示例11: outputDataUse

import cucumber.api.Scenario; //導入依賴的package包/類
/**
 * Output the values of any dataset entries used 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.
 * @param scenario  The scenario just completed
 */
private void outputDataUse(Scenario scenario) {
    List<String> keys = driverWrapper.getAllDataKeys();
    if (keys.size() > 0) {
        scenario.write("The following data values were used in this test run:");
        for (String key: keys) {
            scenario.write("{" + key + "} => " + driverWrapper.getData(key));
        }
    }
}
 
開發者ID:dvsa,項目名稱:mot-automated-testsuite,代碼行數:15,代碼來源:LifecycleHooks.java

示例12: 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);
    }
}
 
開發者ID:dvsa,項目名稱:mot-automated-testsuite,代碼行數:30,代碼來源:LifecycleHooks.java

示例13: 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);
    }
}
 
開發者ID:dvsa,項目名稱:mot-automated-testsuite,代碼行數:29,代碼來源:LifecycleHooks.java

示例14: runTestCase

import cucumber.api.Scenario; //導入依賴的package包/類
/**
 * Executes the specified TestCase and returns the Execution. If a scenario
 * is specified and the testserver.cucumber.logfolder system property is set,
 * the generated recipe will be written to the specified folder.
 *
 * It is possible to temporarily "bypass" recipe execution by specifying
 * a testserver.cucumber.silent property - in which case testcases will not be
 * submitted to the server, but still logged to the above folder.
 *
 * @param testCase the TestCase to execute
 * @param scenario the Cucumber scenario used to generate the specified Recipe
 * @return the TestServer Execution for the executed TestCase
 * @throws com.smartbear.readyapi.client.execution.ApiException if recipe execution failes
 */

public Execution runTestCase(TestCase testCase, Scenario scenario) {

    TestRecipe testRecipe = new TestRecipe(testCase);

    if (LOG.isDebugEnabled()) {
        LOG.debug(testRecipe.toString());
    }

    String logFolder = System.getProperty( "testserver.cucumber.logfolder", null );
    if( scenario != null && logFolder != null ){
        logScenarioToFile(testRecipe, scenario, logFolder);
    }

    return async ? executor.submitRecipe( testRecipe ) : executor.executeRecipe(testRecipe);
}
 
開發者ID:readyapi,項目名稱:testserver-cucumber,代碼行數:31,代碼來源:CucumberRecipeExecutor.java

示例15: beforeFeature

import cucumber.api.Scenario; //導入依賴的package包/類
@Before(order=4)
public void beforeFeature(Scenario scenario) throws SQLException, ClassNotFoundException {
    logger.info("Start scenario: " + scenario.getName());

    //To run the after hook methods in the last scenario of the features
    currentFeature = scenario.getId().split(";")[0];
    System.out.println(currentFeature);
    if (!currentFeature.equals(lastFeature)) {
        executeAfterHookMethod();
        lastFeature = currentFeature;
        featureFlag = false;
    }
}
 
開發者ID:PenielDVP,項目名稱:RoomManagerAutomation,代碼行數:14,代碼來源:FeatureHooks.java


注:本文中的cucumber.api.Scenario類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。