How do I run a PHPUnit Selenium test without having a new browser window run for each function?

前端 未结 5 1833
逝去的感伤
逝去的感伤 2021-01-13 05:06

I am trying to run a selenium test case using PHPUnit. And the first thing I do is trying the login function, this works perfect but then I want to run a function to check i

相关标签:
5条回答
  • 2021-01-13 05:29

    Okej so I guess you can just call the function directly from another function like so:

    public function testOne
    {
    #code
    $this->Two();
    }
    
    public function Two()
    {
    #code
    $this->Three();
    }
    
    public function Three()
    {
    #code
    }
    

    and so on, this will just run the next function without a new browser, however, if it fails anywhere in any test the whole test is stoped so the feedback wont bee as good as individual tests.

    0 讨论(0)
  • 2021-01-13 05:29

    You can call PHPUnit_Extensions_SeleniumTestCase::shareSession(true) to enable browser window reuse.

    In the manual it says:

    From Selenium 1.1.1, an experimental feature is included allowing the user to share the session between tests. The only supported case is to share the session between all tests when a single browser is used. Call PHPUnit_Extensions_SeleniumTestCase::shareSession(true) in your bootstrap file to enable session sharing. The session will be reset in the case of not successul tests (failed or incomplete); it is up to the user to avoid interactions between tests by resetting cookies or logging out from the application under test (with a tearDown() method).

    0 讨论(0)
  • 2021-01-13 05:32

    make assetrions in one function because this is functional test. i am new to phpunit and selenium too, but I successfully test all in one like this:

    public function testAuth(){  
    
    $this->open('register.php&XDEBUG_SESSION_START=PHPSTORM');
    $this->assertTextPresent('Register');
    $this->type('name=email', "...");
    $this->type('name=firstname', "...");
    $this->type('name=lastname', "...");       
    $this->type('name=password', "...");
    $this->type('name=verifyPassword', "...");
    $this->click("reg-butt");
    $this->waitForPageToLoad("5000");
    $this->assertTextPresent('Profile');
    $this->open('logout.php');
    $this->assertTextPresent('text from redirect page');
    $this->open('login.php');
    .....
    
    }
    
    0 讨论(0)
  • 2021-01-13 05:35

    To share browser sessions in Selenium2TestCase, you must set sessionStrategy => 'shared' in your initial browser setup:

    public static $browsers = array(
        array(
            '...
            'browserName' => 'iexplorer',
            'sessionStrategy' => 'shared',
            ...
        )
    );
    

    The alternative (default) is 'isolated'.

    0 讨论(0)
  • 2021-01-13 05:35

    An elegant way to set the session shared is to use PHPUnit's setUpBeforeClass() method:

    public static function setUpBeforeClass()
    {
        self::shareSession(true);
    }
    
    0 讨论(0)
提交回复
热议问题