add current_page and back

master
Kanezoh 2021-06-16 14:22:29 +09:00
parent 316a3de570
commit 76d09d6802
3 changed files with 21 additions and 4 deletions

View File

@ -91,4 +91,13 @@ describe "Mechanize Agent test" do
agent.history.size.should eq 2
agent.history.last.title.should eq "page_title"
end
it "can back previous page" do
agent = Mechanize.new
agent.get("http://example.com/")
agent.get("http://html_example.com/")
agent.current_page.title.should eq "page_title"
agent.back
agent.current_page.title.should eq ""
end
end

View File

@ -60,6 +60,14 @@ class Mechanize
@agent.request_headers = request_headers
end
def current_page
@agent.current_page
end
def back
@agent.history.pop
end
def submit(form)
case form.method.upcase
when "POST"

View File

@ -37,6 +37,10 @@ module MechanizeCr
end
end
def current_page
@history.last
end
def back
@history.pop
end
@ -102,10 +106,6 @@ module MechanizeCr
end
end
private def current_page
@history.last
end
private def reset_request_header_cookies
request_headers.delete("Cookie")
end