org.testng.TestNGException: для метода tearDown требуется 1 параметр, но в аннотации @Configuration указано 0 - PullRequest
0 голосов
/ 20 мая 2018

Я не могу понять, что требуется в качестве параметра, может кто-нибудь помочь мне с этим. Я написал ниже код: -

 @Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "features")
    public void feature(CucumberFeatureWrapper cucumberFeature) throws Exception {
        testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
 }

@AfterMethod(alwaysRun = true)
public void tearDown(Scenario scenario) {
    scenario.write("Finished Scenario"); 
    if (scenario.isFailed()) {      
    String screenshotName = scenario.getName().replaceAll(" ", "_");
        try {
            File sourcePath =((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
            File destinationPath = new File(System.getProperty("user.dir") + "/Screenshots/" + screenshotName + ".png");                
            Files.copy(sourcePath, destinationPath); 
            Reporter.addScreenCaptureFromPath(destinationPath.toString());
        } catch (IOException e) {
        } 
        driver.close();
    }   
    }

И я получаю ошибку ниже: -

СБОЙ КОНФИГУРАЦИЯ: @AfterMethodtearDown org.testng.TestNGException: Метод tearDown требует 1 параметров, но в аннотации @Configuration было указано 0.

1 Ответ

0 голосов
/ 20 мая 2018

Нельзя передать объект Cucumber Scenario методу конфигурации TestNg.AfterMethod будет вызываться TestNg и не сможет внедрить объект Scenario.Список объектов, которые вводятся автоматически, можно найти здесь: http://testng.org/doc/documentation-main.html#native-dependency-injection

. Или используйте аннотацию After Cucumber и передайте объект Scenario.

@cucumber.api.java.After
public void tearDown(Scenario scenario)

Или используйтеAfterMethod TestNg и передать объект ITestResult.

@org.testng.annotations.AfterMethod
public void tearDown(ITestResult result)
...