giorgiosironi / phpunit-selenium

Selenium RC integration for PHPUnit
http://www.phpunit.de/
Other
601 stars 270 forks source link

There is currently no active session to execute the 'byId' command. #275

Open ndeztea opened 10 years ago

ndeztea commented 10 years ago

Hi,

Ok I tried to get the element byid, this is the code :

class Auth  extends Core
{
    protected $listUser;

    public function __construct(){

        $listUser['admin_pass_a'] = 'admin';
        $listUser['admin_pass_a'] = 'admin';

        $listUser['user_a'] = 'aa';
        $listUser['pass_a'] = 'aaa';

    }

    public function login($user){

        $this->byId('username')->value($this->listUser['user_'.$user]);
        $this->byId('password')->value($this->listUser['pass_'.$user]);
        $this->byId('submit')->click();  
    }

    public function logout(){
        $this->byId('submit')->getText('title="logout"');  
    }

}

and this is the core code :

class Core extends PHPUnit_Extensions_Selenium2TestCase
{

    public function start(){
        $this->setBrowser(TEST_BROWSER);
        $this->setBrowserUrl(TEST_URL);

    }

}

class LoginTest extends Core
{
    protected $auth;

    public function setUp(){
        $this->start();

        $this->auth = new Auth();

    }

    public function testLogin(){
        $this->prepareSession();
        $this->url(TEST_URL);

        $this->auth->login('a');
        //$this->assertEquals('Recent Activities', 'as');
    }

    public function testLogout(){
        $this->auth->logout();
    }

    protected function tearDown()
    {
        // Close driver
    }
}

And when I run the test file, I get this error :

PHPUnit_Extensions_Selenium2TestCase_Exception: There is currently no active session to execute the 'byId' command. You're probably trying to set some option in setUp() with an incorrect setter name. You may consider using setUpPage() instead.

Can somebody help me?

ndeztea commented 10 years ago

If I seperate the file I get that issue, but if I make just one file for testing this is working fine..

giorgiosironi commented 10 years ago

During setUp() the browser has not yet been started, since it's the place when you choose browser version and where Selenium runs. The error message is suggesting you to move setUp() code in setUpPage(), an hook called later in the process

On Thu, Nov 28, 2013 at 11:44 AM, ndeztea notifications@github.com wrote:

If I seperate the file I get that issue, but if I make just one file for testing this is working fine..

— Reply to this email directly or view it on GitHubhttps://github.com/sebastianbergmann/phpunit-selenium/issues/275#issuecomment-29455071 .

Giorgio Sironi (@giorgiosironi) http://giorgiosironi.com http://giorgiosironi.blogspot.com/

ndeztea commented 10 years ago

Thank you for your answer, can you show me the proper code for that, please?

giorgiosironi commented 10 years ago

Here you go https://github.com/sebastianbergmann/phpunit-selenium/blob/master/Tests/Selenium2TestCase/SetUpPageTest.php