开发者

How to access a stored value in PHPUnit_Extensions_SeleniumTestCase

How can I store a value within Selenium-RC (through PHPUnit) and then retrieve/access it later using PHPUnit?

Suppose I run a command like the following in a test:

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

If I understand the Selenium API documentation correctly, I could access this data using javascript{storedVars['foo']} using good 'ol fashioned Selenese. It should 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's a simple test I've run:

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

The output of which is "foo" (among the other standard PHPUnit output), while I expect it should be "bar". It's just giving me back the name of the expression, not its value.

Can anyone开发者_开发百科 with experience in this give me some guidance?


Good posts in this thread, but looks like no 100% working answer so far.

Based on the Selenium reference here

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

It would seem the correct code syntax would be:

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

I haven't tested that exactly, but doing something similar with

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

did the trick for me.


The PHPUnit Selenium Testcase driver actually understands storeExpression and getExpression; have a look at its source code. You can do

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

and

$this->getExpression('foo');


As Selenium Stores the expression result in second argument it stores value in "bar" and when u need to call it you should call the stored name to get the expression.

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

May this helps you it worked for me.

EDIT :

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

The First Evaluated will give the evaluated output for expression and the second will show the expressed output. The secound is used to verify that the specified expression is genrated or not by the alert.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜