Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

assertPageAddress() fails when passing an link as parameter #320

Open
yehee opened this issue Apr 5, 2018 · 0 comments
Open

assertPageAddress() fails when passing an link as parameter #320

yehee opened this issue Apr 5, 2018 · 0 comments

Comments

@yehee
Copy link

yehee commented Apr 5, 2018

Hi,

I encountered an issue with testing the current URL followed by clicking an element. I have no problem testing any internal path (e.g I should be on "/" or I am on "/"). However, the test with the line:

Then I should be on "https://www.example.ca"

it gives me an error that says

Current page is "/", but "" expected. (Behat\Mink\Exception\ExpectationException)

I created AfterStep method that prints out the current URL, and I could see that the link is not broken and is redirecting the page to the right URL as it is printing out the address I am expecting to see.

Edit: cleanUrl method is being called in addressEquals, and the method returns / when https://www.example.ca is passed as a parameter which makes sense why the test is failing. Is there a way to get away from this issue other than implementing a custom method?

Edit: Here is my work around this issue:

  /**
  * @Then current url is :page
  */
  public function currentUrlIs($page)
  {
    $this->addressEquals($this->locatePath($page));
  }
  
  /**
  * @return true if the given address matches with the current url
  *         false, otherwise
  */
  private function addressEquals($page)
  {
    $expected = $page;
    $actual = $this->getSession()->getCurrentUrl();
    $this
      ->assert(strpos($actual,$expected) !== false, sprintf('Current page is "%s", but "%s" expected.', $actual, $expected));
  }
  
  /**
  * @throw Exception when the condition is not met
  */
  private function assert($condition, $message) {
    if ($condition) {
      return;
    }
    throw new \Exception($message);
  }

Any help would be appreciated. Thank you :)

@yehee yehee closed this as completed Apr 19, 2018
@yehee yehee reopened this Apr 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant