在黄瓜的@Given @When @Then之间传递变量

时间:2019-07-11 10:49:36

标签: java cucumber

我在下面声明了我的功能。 我的函数之一返回应用程序的签名(objEvaluationPage.getApplicationSignature) 在第一个@Given中,我将此函数返回的值传递给签名变量,我在第一个@Given的objEvaluationPage.setSignature(signature)中成功使用了该值。

我也想在第二个@Given中使用签名变量:objEvaluationPage.setSignature(signature); 但是没有传递签名的值,在控制台中(从执行日志的第一行开始),我从System.out.println(“ signature2:” + signature);返回了signature2:null;

为什么我不能在第二个@Given中使用变量签名的值?

package opi.features.evaluation;

import com.codeborne.selenide.Selenide;
import com.github.javafaker.Faker;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;
import cucumber.api.java.en.Then;
import opi.pages.evaluation.EvaluationPage;
import opi.pages.evaluation.applicationView.PermissionsPage;
import opi.pages.programs.LoginPage;
import opi.utils.PropertiesReader;

import java.io.IOException;
public class ExpertFeatures {
    public String signature;
    String programName = "P";
    EvaluationPage objEvaluationPage = new EvaluationPage();
    LoginPage objLoginPage = new LoginPage();
    PermissionsPage objPermissionsPage = new PermissionsPage();
    Faker faker = new Faker();


    @Given("^UserEmployee finds application with status formal evaluation accepted$")
    public void useremployeeFindsApplicationWithStatusFormalEvaluationAccepted() throws IOException, InterruptedException {
        Selenide.open( new PropertiesReader().getEvaluationUrl());
        objLoginPage.login("mateuszkrasny@gmail.com","Wniosek1!");
        objEvaluationPage.selectAllPrograms();
        objEvaluationPage.deselectAllPrograms();
        objEvaluationPage.setProgram(programName);
        objEvaluationPage.selectAllStatuses();
        objEvaluationPage.deselectAllStatuses();
        objEvaluationPage.checkFormalPositive();
        signature = objEvaluationPage.getApplicationSignature();
        objEvaluationPage.checkFirstAvaiableApplication();
        System.out.println("signature: "+signature);
        objEvaluationPage.setSignature(signature);
    }

    @When("^UserEmployee adds expert to application$")
    public void userEmpAddsExpertToApplication() throws IOException, InterruptedException {
      //  objEvaluationPage.clickAssignReviewer();
       // objEvaluationPage.setExpert("Krasny Mateusz");
      //  Thread.sleep(2000);
    }

    @Then("^UserExpert is added to application$")
    public void userExpIsAddedToApplication() throws IOException, InterruptedException {

    }



    @Given("^UserEmployee is on permissions page of application with added expert$")
    public void userEmpIsOnPermissionsPageOfApplicationWithAddedExpert() throws IOException, InterruptedException {
        objEvaluationPage.selectAllStatuses();
   
        System.out.println("signature2:"+signature);
        objEvaluationPage.setSignature(signature);


        objEvaluationPage.clickOnFirstAvaiableApplication();

        objPermissionsPage.clickPermissionTab();
 



    }

    @When("^UserEmployee removes expert from application$")
    public void useremployeeRemovesExpertFromApplication() throws InterruptedException {
       objPermissionsPage.clickDeleteBtn();
       objPermissionsPage.addDeleteNote(faker.twinPeaks().quote());
  
    }

    @Then("^UserExpert was removed from application$")
    public void userexpertWasRemovedFromApplication() {

    }
}

1 个答案:

答案 0 :(得分:0)

好吧,我用第二个@Given

objEvaluationPage.setSignature(ExpertFeatures.signature);

代替

objEvaluationPage.setSignature(signature);

对我来说很烦