Selenium and the lost session

I’m performing a simple functional test with phpunit and selenium.

A variable is stored in the session using Yii::app()->user->setState()

This works well and it can be retrieve using getState(). Of course the user needs to be logged in to test this.

My problem start with testing this. I use phpunit and selenium to make a user log in. During login the mentioned variable is set in the siteController using setState.

When getState() is run next, it turns out the complete session is empty. Somehow the session is lost and I do not understand why.

Here is the test file


class SetAccountTest extends WebTestCase


    protected $coverageScriptUrl = 'http://localhost/phpunit_coverage.php';

    public $fixtures=array(


	public function login()



            $this->type("LoginForm_email", "");

            $this->type("LoginForm_password", "test");






	public function testSetAccount_1()



	    $acId = Yii::app()->user->getState('acId');

            $this->assertEquals(1, $acId);

            // $acId is null




Does anyone of you guys have experienced this issue?


I did.

When running your test you have 2 instances of CWebApplication with different session_id/session files.

One created by index-test when selenium-rc launch your browser and the other by phpunit when it runs the bootstrap file.

In your test file Yii::app() refers to the ‘bootstrap created’ instance with an undefined $_SESSION.

You can retrieve session data by reading session file.

Testing_Selenium::getCookie will give you the browser session_id to find the session file.

You will have to override CHttpSession::writeSession to make this file readable.

Then you will be able to extract what you need.

This is what I have done for now but next time I will consider using CDbHttpSession