Skip to main content

Behat Using the Browser History

The Mink session gives you access to the browser history, you can perform refresh, back and forward action on browser. Consider you have following scenario for autopract.com website

  @browser
  Scenario: verify browser
    When I click on shop now on banner
    Then I should see "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
    And I refresh the page
    When I press browser back button
    Then I should see "TOP COLLECTION"
    When I press browser forward button
    Then I should see "Lorem Ipsum is simply dummy text of the printing and typesetting industry."

Here we are click on shop now button, then visiting some page and asserting text, after that we are performing refresh operation. Soon after we are clicking on back button and on homepage asserting TOP COLLECTION and after performing forward operation on browser we are asserting same text again.

Here are the corresponding step definitions:

/**
  * @When /^I click on shop now on banner$/
  */
public function iClickOnShopNowOnBanner()
{
    $this->getSession()->getPage()->find('xpath', "(//div[@class='slider-contain']//a)[3]")->click();
}

/**
  * @Given /^I refresh the page$/
  */
public function iRefreshThePage()
{
    $this->getSession()->reload();
}

/**
  * @When /^I press browser back button$/
  */
public function iPressBrowserBackButton()
{
    $this->getSession()->back();
}

/**
  * @When /^I press browser forward button$/
  */
public function iPressBrowserForwardButton()
{
    $this->getSession()->forward();
}

In last 3 step definition you can see we are performing refresh, back and forward action on browser.

Tags
Submitted by tgoswami on April 15, 2021

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.