Check external redirection with Codeception

I want to check something like this:

<?php

$I->amOnPage('/go/google');
$I->seeCurrentUrlEquals('http://google.com');

But I get the 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"

The idea is simply to check if users have been redirected to an external resource.

+4
source share
6 answers

The Codeception methods seeCurrentUrlEquals()and seeCurrentUrlMatches(), unfortunately, are incorrectly named, because they do not allow us to say that they are made against the entire URL, but rather only against parts of the URI.

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 script you can just do something like:

$I->seeFullCurrentUrlEquals('google.com');
+4
source

I would improve @rickroyce's comment by replacing line 2

$I->wait(2);

with something like

$I->waitForElement('#gbqfq', 30);

google , , 2 , .

<?php

$I->amOnPage('/go/google');
$I->waitForElement('#gbqfq', 30);
$I->seeCurrentUrlEquals('http://google.com');

( , , :))

+2

@gopherIT, Codeception URL- .

phpBrowser, .



  1. GaryJones ( ) Github:

    https://gist.github.com/GaryJones/284eea905cff882cc7cb

    , ...

    $I = new RedirectsTester($scenario);
    $I->wantTo('check 301 redirects are working');
    
    // First, test /login/ page gets rewritten to https://
    $I->seePermanentRedirectToHttpsFor('login/');
    $I->seePermanentRedirectToHttpsFor('login/?redirect_to=foo');
    
    // For all other redirects, a Location header is sent, so we stop the redirect
    // and just check that header instead.
    $I->followRedirects(false);
    
    // External
    $I->sendHead('facebook');
    $I->seePermanentRedirectTo('https://www.facebook.com/DanielsTrading');
    
    // Internal link
    $I->sendHead('don-debartolo/access');
    $I->seePermanentRedirectTo('ddebartolo/#account');
    

    , .

+1

? . "/go/google", URL-, , . .

Try:

<?php

$I->amOnPage('/go/google');
$I->wait(2);
$I->seeCurrentUrlEquals('http://google.com');

0

, :

$uri_to_redirect = '/use_stackoverflow';
$redirected_to_uri = '/love_stackoverflow';

$I->wantToTest( 'if rediecting works well from : '.$uri_to_redirect.' to : '.$redirected_to_uri );
$I->amOnUrl( $mydomain.$uri_to_redirect );
$I->seeCurrentUrlEquals( $redirected_to_uri );

, "seeCurrentUrlEquals" URI, URL.

0

?

$I->amOnPage('/go/google');
$I->seeResponseCodeIs(302);
$I->seeHttpHeader('Location', 'http://google.com');
-1

All Articles