diff --git a/spec/agent_spec.cr b/spec/agent_spec.cr index 9ed4304..f216454 100644 --- a/spec/agent_spec.cr +++ b/spec/agent_spec.cr @@ -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 diff --git a/src/mechanize.cr b/src/mechanize.cr index 77da83f..1d127e9 100644 --- a/src/mechanize.cr +++ b/src/mechanize.cr @@ -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" diff --git a/src/mechanize/http/agent.cr b/src/mechanize/http/agent.cr index a720407..833c224 100644 --- a/src/mechanize/http/agent.cr +++ b/src/mechanize/http/agent.cr @@ -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