填写包含20多个字段的网络表单的最佳方法是什么? 我可以使用数据表和场景大纲的组合来避免为表单中的每个字段编写步骤吗?
我写了这样的功能..但是不知道如何为此实现步骤定义? 有人请帮忙..
Scenario Outline: Test successful registration of a new user
Then I enter email address of new user as "<customerEmail>"
And I click on CreateAccount button
Then I enter my personal informations
| Title | CustomerFirstName | CustomerLastName | Email | Password | DOB |
| <title> | <cFname> | <cLname> | <email> | <pwd> | <dob> |
And I enter my address informations
| FirstName | LastName | Company | Address | AddressLine2 | City | State
| ZipCode | Country |
| <fname> | <lname> | <company> | <addr1> | <addr2> | <city> | <state> |
<zip> | <country> |
And I enter additional informations
| AdditionalInformation | HomePhone | MobilePhone | AlternateAddress |
| <remarks> | <homephone> | <mobile> | <addr3> |
When I click on Register button
Then I redirected to order summary page
Examples:
| customerEmail | <title> | <cFname> | <cLname> | <email> | <pwd> | <dob> |
<fname> | <lname> | <company> | <addr1> | <addr2> | <city> | <state> | <zip>
| <country> | <remarks> | <homephone> | <mobile> | <addr3> |
| abc@gmail.com | f | g | f | t | y | y | y | y | y | y | y | h | d | e | e |
r | b | w | u |
答案 0 :(得分:0)
似乎更适合作为场景而不是场景线。缩短版本的场景比您使用的版本。 exaples表格中的标题包含&#39;&lt;&gt;&#39;这是没有必要的。
功能文件
Scenario Outline: Test successful registration of a new user
Then I enter email address of new user as "<customerEmail>"
Then I enter my personal informations
| title | customerFirstName | customerLastName |
| <title> | <cFname> | <cLname> |
And I enter my address informations
| firstName | lastName | company |
| <fname> | <lname> | <company> |
Examples:
| customerEmail | title | cFname | cLname | fname | lname | company |
| abc@gmail.com | f | g | f | e | r | b |
StepDefinition -
public class FormSteps {
private User user = new User();
@Then("^I enter email address of new user as \"([^\"]*)\"$")
public void iEnterEmailAddressOfNewUserAs(String email) {
//Input details to webpage and store for later use
user.setEmail(email);
}
@Then("^I enter my personal informations$")
public void iEnterMyPersonalInformations(List<User.UserPersonal> userPers) {
//Input details to webpage and store for later use
user.setPersonalDetails(userPers.get(0));
System.out.println(user);
}
@Then("^I enter my address informations$")
public void iEnterMyAddressInformations(List<User.UserAddress> userAddr) {
//Input details to webpage and store for later use
user.setAddressDetails(userAddr.get(0));
System.out.println(user);
}
}
具有内部类的用户类 - 为附加信息添加新的内部类。添加其他变量。
public class User {
private UserPersonal personal = new UserPersonal();
private UserAddress address = new UserAddress();
private String email;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public UserPersonal getPersonalDetails() {
return personal;
}
public void setPersonalDetails(User.UserPersonal personal) {
this.personal = personal;
}
public UserAddress getAddressDetails() {
return address;
}
public void setAddressDetails(UserAddress address) {
this.address = address;
}
@Override
public String toString() {
return "User [personal=" + personal + ", address=" + address
+ ", email=" + email + "]";
}
public class UserPersonal {
private String title;
private String customerFirstName;
private String customerLastName;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCustomerFirstName() {
return customerFirstName;
}
public void setCustomerFirstName(String customerFirstName) {
this.customerFirstName = customerFirstName;
}
public String getCustomerLastName() {
return customerLastName;
}
public void setCustomerLastName(String customerLastName) {
this.customerLastName = customerLastName;
}
@Override
public String toString() {
return "UserPersonal [title=" + title + ", customerFirstName="
+ customerFirstName + ", customerLastName="
+ customerLastName + "]";
}
}
public class UserAddress {
private String firstName;
private String lastName;
private String company;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
@Override
public String toString() {
return "UserAddress [firstName=" + firstName + ", lastName="
+ lastName + ", company=" + company + "]";
}
}
}
这可以很容易地切换到一个场景。像步骤定义等一切都保持不变。
Scenario: Test successful registration of a new user
Then I enter email address of new user as "abc@gmail.com"
Then I enter my personal informations
| title | customerFirstName | customerLastName |
| f | g | f |
And I enter my address informations
| firstName | lastName | company |
| e | r | b |
答案 1 :(得分:0)
为您的数据集合命名。让我们说它是一种税收形式。而不是让你的功能定义如何填写表单只是在填写表格时填写并让下面的代码处理细节
所以你最终会得到一个步骤
auth_permissions
并将其实现为
When I fill in my tax form
现在创建一个帮助方法来填写税收
When "I fill in my tax form" do
fill_in_tax_form
end
现在因为你实际上用编程语言填写表单,你可以做各种很酷的事情来使这简单得多。例如,我填充向导的步骤之一使用以下方法
module TaxFormStepHelper
def fill_in_form
end
end
通过将您填写表单的方式推送到较低级别的测试代码中,您可以使您更加简单,同时它们变得更加强大。
如果你想处理悲伤的路径,你可以做一些事情,比如
def fill_in_electric_meter_details
fill_in_common_meter_details
# 'debt_clearance_meter_serial_number' is prepopulated from property
fill_in 'debt_clearance_screen_a', with: 'a'
fill_in 'debt_clearance_screen_b', with: 'b'
fill_in 'debt_clearance_screen_f', with: 'f'
fill_in 'debt_clearance_screen_g', with: 'g'
end
When I fill in my tax form
And my employment status is not correct
Then ...
正常填写表格
When
覆盖就业状态,因此不正确
在cuking时绝对不需要使用大型示例表。你所做的就是让你的功能更难以阅读,你的步骤定义更难写。
希望对你有用:)