2021-06-18 23:00:33 +02:00
|
|
|
require "../spec_helper"
|
|
|
|
|
2021-08-17 18:30:01 +02:00
|
|
|
WebMock.stub(:get, "example.com/form/fields").to_return(body: <<-BODY
|
2021-06-18 23:00:33 +02:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>page_title</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<form action="post_path" method="post" name="sample_form">
|
2021-06-18 23:42:44 +02:00
|
|
|
<input type="text" name="name" value="kanezoh">
|
2021-06-19 00:09:02 +02:00
|
|
|
<input type="text" name="name" value="dareda">
|
2021-06-18 23:50:35 +02:00
|
|
|
<input type="text" name="email" class="emailClass" id="emailID">
|
2021-06-18 23:00:33 +02:00
|
|
|
</form>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
BODY
|
|
|
|
)
|
|
|
|
|
|
|
|
describe "Form Fields" do
|
|
|
|
agent = Mechanize.new
|
|
|
|
page = agent.get("http://example.com/form/fields")
|
|
|
|
form = page.forms[0]
|
|
|
|
it "returns field attribute" do
|
|
|
|
field = form.fields.first
|
|
|
|
field.type.should eq "text"
|
|
|
|
field.name.should eq "name"
|
2021-06-18 23:42:44 +02:00
|
|
|
field.value.should eq "kanezoh"
|
|
|
|
field.raw_value.should eq "kanezoh"
|
2021-06-18 23:00:33 +02:00
|
|
|
end
|
2021-06-18 23:50:35 +02:00
|
|
|
|
|
|
|
it "returns DOM id and class" do
|
|
|
|
field = form.fields.first
|
|
|
|
# dom_id and class returns empty string if there are no id, class
|
|
|
|
field.dom_id.should eq ""
|
|
|
|
field.dom_class.should eq ""
|
2021-06-19 00:09:02 +02:00
|
|
|
field = form.fields[2]
|
2021-06-18 23:50:35 +02:00
|
|
|
field.dom_id.should eq "emailID"
|
|
|
|
field.dom_class.should eq "emailClass"
|
|
|
|
end
|
2021-06-19 00:09:02 +02:00
|
|
|
|
|
|
|
it "can be found by field_with method" do
|
|
|
|
name_field = form.field_with("name")
|
|
|
|
name_field.name.should eq "name"
|
2021-06-19 00:55:11 +02:00
|
|
|
|
|
|
|
email_field = form.field_with({"id" => "emailID"})
|
|
|
|
email_field.name.should eq "email"
|
2021-06-19 00:09:02 +02:00
|
|
|
end
|
|
|
|
|
2021-08-11 00:17:38 +02:00
|
|
|
it "can be found by fields_with method, argument type: Hash" do
|
2021-06-19 00:09:02 +02:00
|
|
|
name_fields = form.fields_with("name")
|
|
|
|
name_fields.size.should eq 2
|
|
|
|
name_fields[0].name.should eq "name"
|
|
|
|
end
|
2021-08-11 00:17:38 +02:00
|
|
|
|
|
|
|
it "can be found by fields_with method, argument type: NamedTuple" do
|
|
|
|
name_field = form.field_with("name")
|
|
|
|
name_field.name.should eq "name"
|
|
|
|
|
|
|
|
email_field = form.field_with({id: "emailID"})
|
|
|
|
email_field.name.should eq "email"
|
|
|
|
end
|
2021-06-18 23:00:33 +02:00
|
|
|
end
|