I want to check something like this:
<?php
$I->amOnPage('/go/google');
$I->seeCurrentUrlEquals('http://google.com');
But I get error:
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://google.com'
+''
Scenario Steps:
2. I see current url equals "http://google.com"
1. I am on page "/go/google"
Idea is just to check if users was redirected to external resource.
Just select the browser user-agent to test your redirect. Check your URL redirect for accuracy. Do you use search engine friendly redirections like to many redirects or do you loose link juice for seo by redirects using HTTP Statuscode 301 vs. 302. Check now! This Redirect Checker supports several features like:
Codeception allows you to execute actions in concurrent sessions. The most obvious case for this is testing realtime messaging between users on a site. In order to do it, you will need to launch two browser windows at the same time for the same test. Codeception has a very smart concept for doing this. It is called Friends:
But thanks to the web redirection, those reach the updated web address regardless of typing in the old URLs. Based on the use case, here are various types of redirections: 301 Redirect: This is a permanent redirection meaning the old web property is no longer available.
This can be useful to see the entire path and the final server to which a short URL points. And you can check the status code of the redirects and opt for the URL shortening service using 301 redirects for maximum SEO advantage.
Codeception's seeCurrentUrlEquals()
and seeCurrentUrlMatches()
methods are, unfortunately, misnamed as they do not allow assertions to be made against the entire URL but rather only against the URI parts.
I solved this by declaring the following method in my Helper class:
public function seeFullCurrentURLEquals($value)
{
return ($this->getModule('PhpBrowser')->client->getHistory()->current()->getUri() == $value);
}
Then, in the scenario, you can simply do something like:
$I->seeFullCurrentUrlEquals('google.com');
I would improve @rickroyce´s comment by swapping out line 2
$I->wait(2);
with something like
$I->waitForElement('#gbqfq', 30);
which waits for the google search input field and is more robust then just assuming 2 seconds is enough that the page is loaded.
The full example would be then
<?php
$I->amOnPage('/go/google');
$I->waitForElement('#gbqfq', 30);
$I->seeCurrentUrlEquals('http://google.com');
(Normally it would put the addition as comment but since I do not have enough reputation it is an answer :))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With