How to access stored value in PHPUnit_Extensions_SeleniumTestCase

How to save a value in Selenium-RC (via PHPUnit) and then access / access it later using PHPUnit?

Suppose I run the following command in test mode:

$this->storeExpression( "foo", "bar" ); 

If I understand the Selenium API documentation correctly, I could access this data using javascript{storedVars['foo']} using the good Selenese style. It must contain the value "bar" .

My question is this: how can I access this javascript{storedVars['test']} expression (or, more generally, javascript{storedVars} in PHPUnit?

For example, here is a simple test that I performed:

 public function testStorage() { $this->open('http://www.google.com/'); // for example $this->storeExpression( 'foo', 'bar' ); $foo = $this->getExpression('foo'); echo $foo; } 

The output is "foo" (among other standard PHPUnit output), while I expect it to be a "bar". It just returns me the name of the expression, not its value.

Can anyone with experience with this give me some guidance?

+4
source share
3 answers

Good posts in this thread, but at the moment it seems like a 100% working answer.

Based on selenium link here

http://release.seleniumhq.org/selenium-core/1.0/reference.html#storedVars

It would seem that the correct code syntax would be as follows:

 $this->storeExpression( 'bar', 'foo' ); $foo = $this->getExpression("\${foo}"); 

I have not tested this for sure, but something similar with

 $this->storeHtmlSource('srcTxt'); $val = $this->getExpression('\${srcTxt}'); print $val; 

did the trick for me.

+2
source

PHPUnit Selenium test storeExpression driver really understands storeExpression and getExpression ; look at the source code. You can do

 $this->storeExpression('foo', 'bar'); 

and

 $this->getExpression('foo'); 
+1
source

How Selenium Saves the result of an expression in the second argument, it stores the value in "bar", and when u need to call it, you must call the saved name to get the expression.

  $this->storeExpression( 'foo', 'bar' ); $foo = $this->getExpression("bar"); 

Let it help you, it worked for me.

EDIT:

  $evaluated = $this->getEval("regex:3+3"); $expressed = $this->getExpression("regex:3+3"); 

First Evaluated will give the evaluated result for the expression and the second will show the expressed output. A wrapper is used to verify that the specified expression was highlighted or not by a warning.

0
source

All Articles