1
votes

Using PHP Codeception and WebDriver PHP wrapper (Facebook), is it in general possible to get the environment variables of the actual page request, made by PhantomJS or a real browser used?

Maybe it is just my misunderstanding of the technology behind acceptance tests, but given the fact that a testing framework like Codeception is requesting a page using PhantomJS or a real browser like Chrome or Firefox, I would expect to have access to e.g. the $_SERVER global variable. Unfortunately I can not find any methods providing this in WebDriver Codeception module or Facebook PHP WebDriver wrapper.

Specifically, I have a page which is supposed to use SSL only, so a 301 redirection is expected to happen when visiting the page. I need to have an acceptance test case in Codeception to check just that and checking the $_SERVER['HTTPS'] global variable should do it.

First I tried to match the URL against 'https://' but the WebDriver wrapper method _getCurrentUrl() delivers only the URI part without protocol and host.

Then I tried to get the $_SERVER variable inside custom Helper action, but the one accessed directly looks like it comes from the CLI environment, not a browser request.

2

2 Answers

1
votes

No, you can't access $_SERVER in acceptance tests, because $_SERVER is in server-side and all you have is a client.

If you want to check a complete url, you can use getCurrentURL method of webdriver instance, it can be accessed in the same way as _getCurrentUri method in your helper.

public function checkUrl()
{
  $url = $this->getModule('WebDriver')->webDriver->getCurrentURL();
  //do your checks here
}
2
votes

If already used WebDriver module:

$currentUrl = $I->executeJS('return jQuery(location).attr("href");');