P
P
Pasha2013-08-02 22:34:48
PHP
Pasha, 2013-08-02 22:34:48

PHPUnit + Selenium: Pass multiple sites within one test

To carry out the test, you need to go through several sites, let's say social networking sites, and disable your application in test accounts (in order to later check how it connects to social networks).

I create a new test

class class TestSocialReg extends PHPUnit_Extensions_Selenium2TestCase

Next, in setUp, you need to configure the browser

$this->setBrowser('firefox');
$this->setBrowserUrl('https://www.facebook.com');

If this is not done there, then an error occurs

Undefined index: browserUrl

Next, I create a test

function testDo() {
  
  $this->url('/facebook');
  sleep(1);
  
  $this->setBrowserUrl('http://www.opera.com');
  $this->url('/computer');

  sleep(1);
}

As a result, the transition to the Opera website does not occur, and the final page in the open browser appears

https://www.facebook.com/computer

. That is, the site change line was ignored:

$this->setBrowserUrl('http://www.opera.com');

Is there any way to change the site while the test is running?

I could do this operation in three steps - by creating three different test files for three different sites, but I do not know how to guarantee this in the process of executing all the tests in the directory, these three tests will be executed first. To this question, if anyone knows, I would also be happy to receive an answer.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
m-haritonov, 2013-08-03
@fog

If my memory serves me, url() can accept absolute URLs (with a domain), and setBrowserUrl() can set an empty base path. Those. try fixing your code like this:

function setUp() {
    $this->setBrowser('firefox');
    $this->setBrowserUrl('');
}

function testDo() {
    $this->url('https://www.facebook.com/facebook');
    $this->url('http://www.opera.com/computer');
}

P
Pasha, 2013-08-02
@fog

So far, the only way I've found is quite stupid: Every time in setUp, check a certain status of which sites have already been visited and assign the next one, something like this:

class TestSocialReg extends PHPUnit_Extensions_Selenium2TestCase {
  
  private static $callNumber = 1;
  
  function setUp() {
    $this->setBrowser('firefox');
    
    if (self::$callNumber == 1) {
      $this->setBrowserUrl('https://www.facebook.com');
    } else {
      $this->setBrowserUrl('http://opera.com');
    }
  }
  
  function testDo() {
    $this->url('/facebook');
    sleep(1);
    
    self::$callNumber++;
  }
  
  function testDo2() {

    $this->url('/computer');
    sleep(1);
    
    self::$callNumber++;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question