phpunit-selenium icon indicating copy to clipboard operation
phpunit-selenium copied to clipboard

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

Open ndeztea opened this issue 12 years ago • 4 comments

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 avatar Nov 28 '13 09:11 ndeztea

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

ndeztea avatar Nov 28 '13 10:11 ndeztea

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 [email protected] 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/

giorgiosironi avatar Nov 28 '13 17:11 giorgiosironi

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

ndeztea avatar Nov 28 '13 23:11 ndeztea

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

giorgiosironi avatar Dec 01 '13 10:12 giorgiosironi