The admin user should be able to switch permissions for other user.
## Admin Login
- User must login as "admin" - Navigate to the configuration page - Change permissions for user "john" to "admin" - User "john" should have admin permissions
|id| name | |--|-----------| |1 | Alice | |2 | Bob | |3 | Eve | ## First scenario - Say "hello" to <name>. ## Second scenario - Say "namaste" to <name>.
- Delete the "example" project - Ensure "example" project has been deleted
## Delete multiple projects
- Delete all the projects in the list - Ensure project list is eapty
在上面的示例 spec 中, User is logged in as Mike 和 Navigate to the project page是上下文步骤,它们在任意场景前被定义。这些步骤在每个场景 Delete single project 和 Delete multiple projects 执行之前被执行。
Spec 执行过程应该是:
上下文执行:包含步骤 Sign up for user "mike" 和步骤 Log in as "mike"
Delete single project 场景执行
上下文执行:包含步骤 Sign up for user "mike" 和步骤 Log in as "mike"
Delete multiple projects 场景执行
Tear Down 步骤
Tear Down 步骤在最后一个场景后被定义在 spec 内的步骤。它们允许你在每个场景执行后指定一系列清理步骤。
任何常规的步骤可以作为 tear down 步骤
tear down 步骤在每个 spec 内的场景执行后被执行
Tear Down 语法
___ :三个或者更多的连续下划线指示 tear down 的开始。编写在 tear down 内(在三个或者更多联系的下划线之后)的步骤将被认为是 tear down 步骤。
1 2 3 4 5
---
- tear down step 1 - tear down step 2 - tear down step 3
step("Say <greeting> to <name>", function (greeting, name, done) { try { setTimeout(function () { // Code for step done(); }, 1000); } catch (e) { done(e); } });
// Handling errors in promises with done step("Say <greeting> to <name>", function (greeting, name, done) { // Let promise1 be some promise we need to wait for. promise1.then(done).catch(function (e) { done(e); }); });
在下面的例子中,Create a user "user 1" 和 Create another user "user 2" 属于步骤别名,因为他们有相同的步骤实现,但是表达却各异。
1 2 3 4 5 6 7 8
# User Creation
## Multiple Users
- Create a user "user 1" - Verify "user 1" has access to dashboard - Create another user "user 2" - Verify "user 2" has access to dashboard
1 2 3 4 5 6 7 8
publicclassUsers {
[Step("Create a user <user_name>", "Create another user <user_name>")] publicvoidCreateUser(string user_name) { // create user user_name }
}
1 2 3 4 5 6 7 8
publicclassUsers{
@Step({"Create a user <user_name>", "Create another user <user_name>"}) publicvoidcreateUser(String user_name){ // create user user_name }
}
1 2 3
step(["Create a user <username>", "Create another user <username>"], function (username) { // do cool stuff });
1 2 3
@step(["Create a user <user name>", "Create another user <user name>"]) defcreate_user(user_name): print("create {}.".format(user_name))
1 2 3
step 'Create a user <user name>','Create another user <user name>'do|user_name| // create user user_name end
示例 2
在下面的例子中,两个场景中发送邮件的功能相同,但表述各异。
1 2 3 4 5 6 7 8 9 10
## User Creation
- User creates a new account - A "welcome" email is sent to the user
## Shopping Cart
- User checks out the shopping cart - Payment is successfully received - An email confirming the "order" is sent
1 2 3 4 5 6 7 8
publicclassUsers {
[Step({"A <email_type> email is sent to the user", "An email confirming the <email_type> is sent"})] publicvoidSendEmail(string email_type) { // Send email of email_type } }
1 2 3 4 5 6 7 8
publicclassUsers{
@Step({"A <email_type> email is sent to the user", "An email confirming the <email_type> is sent"}) publicvoidsendEmail(String email_type){ // Send email of email_type } }
1 2 3 4 5
step(["A <email_type> email is sent to the user", "An email confirming the <email_type> is sent"], function (email_type) { // do cool stuff });
1 2 3 4 5 6
from getgauge.python import step
@step(["A <email_type> email is sent to the user", "An email confirming the <email_type> is sent"]) defemail(email_type): print("create {}.".format(email_type))
1 2 3 4
step 'A <email_type> email is sent to the user', 'An email confirming the <email_type> is sent'do|email_type| email_service.send email_type end
This is [an example]([http://getgauge.io](http://getgauge.io) “Title) inline link. [This link](<[http://github.com/getgauge/gauge](http://github.com/getgauge/gauge)>) has no title attribute.
// A before spec hook that runs when tag1 and tag2 // is present in the current scenario and spec. beforeSpec(function () { //implementation }, { tags: [ "tag1", "tag2" ]});
// A after step hook runs when tag1 or tag2 // is present in the currentscenario and spec. // Default tagAggregation value is Operator.AND. afterStep(function () { //implementation }, { tags: [ "tag1", "tag2" ]});
1 2 3 4 5 6 7 8 9 10 11
# 在当前spec和场景中,运行在tag1和tag2标签之前的before spec钩子 @before_spec("<tag1> and <tag2>") defbefore_spec_hook(): print("before spec hook with tag")
// The ``[ContinueOnFailure]`` attribute tells Gauge to continue executing others // steps even if the current step fails.
publicclassStepImplementation { [ContinueOnFailure] [Step("Say <greeting> to <product name>")] publicvoidHelloWorld(string greeting, string name) { // If there is an error here, Gauge will still execute next steps }
// The ``@ContinueOnFailure`` annotation tells Gauge to continue executing other // steps even if the current step fails.
publicclassStepImplementation{ @ContinueOnFailure @Step("Say <greeting> to <product name>") publicvoidhelloWorld(String greeting, String name){ // If there is an error here, Gauge will still execute next steps }
}
// 指定错误类列表 @ContinueOnFailure({AssertionError.class, CustomError.class}) @Step("hello") publicvoidsayHello(){ // code here }
@ContinueOnFailure(AssertionError.class) @Step("hello") publicvoidsayHello(){ // code here }
@ContinueOnFailure @Step("hello") publicvoidsayHello(){ // code here }
1 2 3 4 5
// The ``@ContinueOnFailure`` annotation tells Gauge to continue executing other // steps even if the current step fails.
gauge.step("Say <greeting> to <product>.", { continueOnFailure: true}, function (greeting,product) { });
1 2 3 4 5 6 7
# The ``@ContinueOnFailure`` annotation tells Gauge to continue executing other # steps even if the current step fails.
@continue_on_failure([RuntimeError]) @step("Say <greeting> to <product>") defstep2(greeting,product): pass
1 2 3 4 5 6 7
# The ``:continue_on_failure => true`` keyword argument # tells Gauge to continue executing other steps even # if the current step fails.
step 'Say <greeting> to <name>', :continue_on_failure => truedo|greeting, name| # If there is an error here, Gauge will still execute next steps end