testNg中的BeforeSuite方法在与黄瓜集成时没有初始化值

时间:2017-08-28 14:22:23

标签: java automated-tests cucumber testng cucumber-jvm

如果我是Cucumber和TestNG的新手,请建议我是否遗漏了黄瓜的东西。在此先感谢!!

我在使用黄瓜框架(运行为JUnit Test)执行代码时遇到异常 -

java.lang.IllegalArgumentException: Header value cannot be null
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at restprograms.GrpUpdates.getGroup(GrpUpdates.java:165)
    at resources.StepDefCommon.ValidateGetGroup(StepDefCommon.java:20)
    at ✽.When User get group from webportal(src/resources/FCreateGroup.feature:6)

package resources;
import java.io.IOException;
import org.testng.annotations.Test;
import cucumber.api.java.en.When;
import io.restassured.response.Response;
import restprograms.GrpUpdates;
public class StepDefCommon extends GrpUpdates{

    @When("^User get group from webportal$")
    public void ValidateGetGroup() {
        System.out.println("INFO :: Fetched Group");

        System.out.println("Debuggggggg" + getGroup().asString());

    //  System.out.println(res.asString());

    }
}

当以TestNG代码

运行时,此代码可以按预期运行并执行操作
//  @When("^User get group from webportal$")
@Test
    public void ValidateGetGroup() {
        System.out.println("INFO :: Fetched Group");

        System.out.println("Debuggggggg" + getGroup().asString());

    //  System.out.println(res.asString());

    }
}

我正在初始化" loadProperties"中的所有值。方法如下

public class GrpUpdates {

static Properties prop = new Properties();

/****** Common Group properties *******/
public static String glmsUrl; 
public static String putRequest;
public static String updateRequest;
public static String clientId;
public static String memberFile;
public static String globalURI; 

/******* Group Attribute properties ********/

/*** Loading properties in property file and assigning property values ***/

@BeforeSuite
    public static void loadProperties() throws IOException
    {
        InputStream propertyfile = GrpUpdates.class.getResourceAsStream("env.properties");
        prop.load(propertyfile);

        glmsUrl = "http://" +prop.getProperty("xcapHost")+":"+prop.getProperty("xcaport");
        putRequest = glmsUrl + "/" + prop.getProperty("AUID") + "/" + prop.getProperty("CREATOR") + "/" + prop.getProperty("GROUPURI");
        clientId = prop.getProperty("CLIENTID");    
        memberFile = prop.getProperty("MEMBERS_FILE");
    }       
public Response getGroup()
{
    Response res = given().
                   header("ClientId", clientId).
                   config(RestAssured.config().xmlConfig(XmlConfig.xmlConfig().declareNamespace("test", putRequest))).
                   when().
                   get(putRequest);
//                     then().extract().response().asString();
        return res;
    }
}

获取" getGroup()"

中使用的所有变量的ecxeption

0 个答案:

没有答案