November 01 2013

PHPUnit Selenium get url parameter

Tagged Under : ,

PHPUnit
Just now I wrote PHPUnit test case to try get the url parameter with Selenium. In PHP use $_GET function, you can get all the URL parameter. But it doesn’t work in PHPUnit with Selenium.

To solve it was simple, used “$this->getLocation()” function to get current url and then used PHP “parse_url()” and “parse_str()” to get the parameter.

This is an example that shows how to use it.
$url = parse_url($this->getLocation());
$params = parse_str($url['query']);
Now all the url parameters set inside the $params as an array. To view all the parameters you need print out the $params as below:
print_r($params);

Make a Comment

*

code