2017-09-01 269 views
5

我想在这里的工作场所展示宁静,并向他们展示它与使用jasmine.js相比使用起来有多棒和容易 在基本测试中,我试图做 我的测试说宁静+休息服务

Given we have valid credentials for the client using this test 
    When we try to serach for a medicine '<medicine>' 
    Then we get a valid '<perfLabel>' response with search results 
    |medicine|perflabel| 
    |Salbutamol|perflabel1| 
    |Panadol|perflabel2| 
    |Salbutamol (GA)|perflabel3| 

当我进入下一步

@When("we try to serach for a medicine '(.*)' ") 
    public void tryToSearchUsingEquals(String medicine) 
    { 
    tsApiActions.requestServiceSearchWhichEquals(medicine); 
    } 


In my Step method 



@Step 
    public void requestServiceSearchWhichEquals(String medicine) 
    { 
    host = "http://www.int.abc.com.au/api/cs/v1/terminology-service/trade-product/search-summary?offset=0&limit=20&prefLabel=eq "+medicine+"&sort=prefLabel DESC&cache=false"; 

    requestSend(host); 
    } 

的问题,我已经是

  1. 我如何将变量(Salbutamol,Panadol)注入到uri中?
  2. 如何将此URI放入单独的属性文件并在Step方法中调用它?

任何帮助,非常感谢 感谢

回答

1

RestAssured要求遵循哪些应该被添加到您的sendRequest将方法相同的代码结构:

given(). 
    param("prefLabel", medicine). 
when(). 
    get(URL). 
then(). 
    body(containsString(medicine)); 

URL可以来自属性文件,但是你需要创建一个方法在测试运行之前上传它,然后你必须创建一个getPropety()方法来获得你需要的当前值。

我建议在此阅读官方文档: