5

This is happening to me in a real CodeIgniter project in the Ion Auth authentication library, but for the sake of clarity, I have reduced it to it's simplest form.

The script:

I have this one line script located at http://localhost/~captbaritone/redirect/index.php:

<?php header("Refresh:0;url=https://google.com");¬

In my browser, it redirects to Google.com.

The Test:

To test it I wrote this acceptance test:

<?php
$I = new WebGuy($scenario);
$I->wantTo('Redirect to Google.com');
$I->amOnPage('/index.php');
$I->seeCurrentUrlEquals('https://www.google.com/');

My acceptance.suite.yml looks like this:

class_name: WebGuy
modules:
    enabled:
        - PhpBrowser
        - WebHelper
    config:
        PhpBrowser:
            url: 'http://localhost/~captbaritone/redirect/'

The results:

Codeception PHP Testing Framework v1.7.1
Powered by PHPUnit 3.7.27 by Sebastian Bergmann.

Acceptance Tests (1) -----------------------------------------
Trying to redirect to google.com (RedirectCept.php)       Fail
---------------------------------------------------------------


Time: 460 ms, Memory: 9.75Mb

There was 1 failure:

---------
1) Failed to redirect to google.com in RedirectCept.php
Sorry, I couldn't see current url equals "https://www.google.com/":
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'https://www.google.com/'
+'/~captbaritone/redirect/index.php'

Scenario Steps:
2. I see current url equals "https://www.google.com/"
1. I am on page "/index.php"

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

My Question:

Clearly the PhpBrowser is not obeying the redirect. Changing the redirect to a location header, allows the test to pass, but I don't want to (can't) change my application to fit the test suite.

Is this a bug in Codeception? In PhpBrowser? (I'm not really clear on where one starts and the other begins, or if PhpBrowser is even a separate project.) Or maybe this is a functionality I shouldn't expect from a headless browser?

I should disclose that this is my first time working with a test suite.

Jordan Eldredge
  • 1,587
  • 1
  • 19
  • 25
  • There should be some option to set followRedirect I guess, Please provide links to see this. – ahmad Oct 19 '13 at 10:41
  • 1
    I'm not sure, but maybe it's something to do with `Refresh` not being a header in the [official standards](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)? (Whereas, `Location` is.) – jleft Oct 19 '13 at 11:31
  • @ahmad Where would that option be? In Codeception? – Jordan Eldredge Oct 19 '13 at 16:45
  • @Lefters That sounds like a probable explanation. PhpBrowser didn't implement it because it's non-standard. Do you know where I would go to see if that's an intentional omission or a feature they would be willing to support? – Jordan Eldredge Oct 19 '13 at 16:46
  • just came across this issue. Getting a page that says 'Redirecting to...' instead of the page it should be loading, causing my test to fail. Has any progress been made on this? THx – Adamski Apr 02 '14 at 15:48
  • @Adamski I ended up switching to the Web Driver module with Selenium running Phantom JS. – Jordan Eldredge Apr 03 '14 at 17:08
  • Thanks @JordanEldredge - I am using PhantomJS with PhpBrowser for functional tests.. will try it out with acceptance tests using selenium / web driver too. – Adamski Apr 04 '14 at 08:26
  • Still getting this issue also with WebDriver and PhantomJS.. maybe I need Selenium..? – Adamski Apr 04 '14 at 08:43
  • Realised I did not have the Laravel4 module selected in my acceptance.suite.yml - now it works, thanks for the help! – Adamski Apr 04 '14 at 08:58

1 Answers1

1

This is fixed in a Codeception 2.0:

https://github.com/Codeception/Codeception/issues/625#issuecomment-33281671

I would suggest you upgrade and try again.

seangates
  • 1,467
  • 11
  • 28
  • I can't upgrade to 2.x because it requires phpunit 4.x and we're stuck on 3.7 because of some dependencies. :( Is there any other solution that will work with Codeception 1.x? – floriank Sep 11 '15 at 09:35