2
votes

I use robot framework at following environment.

  • Python 2.7.6
  • robotframework 2.8.7
  • Ubuntu 14.04.3 LTS

I test REST API, with keyword like this.

MyKeyword  
Send Request -> Check Response Status Code -> Return Response content

And I use this keyword in negative case like followings.

Run Keyword And Expect Error    400 != 201    MyKeyword    @args    

In this case, if status code is 401, robot fails with this messages.

Expected error '400 != 201' but got '401 != 201'.

But I want to check that request will be rejected because of client reason,
so I wish status code were 40X.

How can I set Run Keyword And Expect Error ambiguous expected message?

1

1 Answers

1
votes

I think you need to make use of wildcard characters as per the documentation - http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Run%20Keyword%20And%20Expect%20Error

I've never used it before but what I think you need change it to this:

Run Keyword And Expect Error    40? != 201    MyKeyword    @args

Perhaps I've misunderstood the docs as I've never used this before though, in which case I would probably look to catch all errors:

Run Keyword And Expect Error * MyKeyword @args

It looks a little strange to me what you're doing though, should you not be using the variable the response result is returned in and checking against that? i.e. ${response} != 40?