填写超过20个字段的web表单的最佳方法是什么?我可以使用数据表和场景大纲的组合来避免为表单中的每个字段编写步骤吗?
我写的特写是这样的。但不知道如何实现这一步定义?谁来帮忙..。
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 |发布于 2018-05-01 10:13:42
它似乎更适合作为一个场景而不是一个场景大纲。该场景的缩短版本比您所使用的要短。exaples表中的标头具有“<>”,这是不必要的。
特征文件
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 |发布于 2018-05-01 20:52:02
给您的数据集合一个名称。让我们说这是一种纳税形式。与其让您的特性定义表单是如何填充的,不如讨论一下何时填写表单,并让下面的代码处理详细信息。
所以你最终会有一步
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如常填写表单,And覆盖雇用状态,因此不正确。
在裁剪时绝对没有必要使用大型的示例表。这样做只会使您的特性更难阅读,步骤定义更难编写。
希望这对你有用:)
https://stackoverflow.com/questions/50111880
复制相似问题