match 与 print 的工作原理有何不同?
Feature: Create and verify User
Background:
* def createRandomUser =
"""
function() {
const random = Math.floor(Math.random() * 10000);
const email = 'user' + random + '@example.com';
const name = 'Name' + random;
const surname = 'Surname' + random;
return { email: email, name: name, surname: surname };
}
"""
Scenario: Create random user and verify
Given def randomUser = createRandomUser()
When def newUser = call read('CreateNewUser.feature') { randomUser: '#(randomUser)' }
And match newUser.response.email == randomUser.email
And match newUser.response.name == randomUser.name
And match newUser.response.surname == randomUser.surname
Then def usersList = call read('GetAllUsers.feature')
And match usersList.response[-1].email == randomUser.email
And match usersList.response[-1].name == randomUser.name
And match usersList.response[-1].surname == randomUser.surname
在这个例子中,我有用户创建并将他添加到列表中,当我尝试打印
usersList.response[-1]
时,我收到null,但是当我将其与randomUser.email
匹配时,它显示true,所以为什么打印显示null而匹配显示它有实际价值吗?然后我打印了randomUser.email
,它显示了创建的电子邮件
我尝试打印
usersList.response[-1]
,而打印usersList.response
显示响应中的所有值,还usersList.response[usersList.response.length - 1]
显示正确的邮件不为空
简短的回答,
print
在右侧采用“正常”JS,但match
默认处理JSON路径。
用圆括号括起来就可以使用JS。例如:
* def foo = [1, 2]
* print foo[foo.length - 1]
* match (foo[foo.length - 1]) == 2