开发者

Is it meaningful to verifyText() on an element that has just had type() executed on it?

开发者 https://www.devze.com 2023-03-09 08:07 出处:网络
I\'m curious about whether the following functional test is possible. I\'m working with PHPUnit_Extensions_SeleniumTestCase with Selenium-RC here, but the principle (I think) should apply everywhere.

I'm curious about whether the following functional test is possible. I'm working with PHPUnit_Extensions_SeleniumTestCase with Selenium-RC here, but the principle (I think) should apply everywhere.

Suppose I execute the foll开发者_高级运维owing command on a particular div:

function testInput() {
    $locator = $this->get_magic_locator(); // for the sake of abstraction
    $this->type( $locator, "Beatles" ); // Selenium API call
    $this->verifyText( $locator, "Beatles" ); // Selenium API call
}

Conceptually, I feel that this test should work. I'm entering data into a particular field, and I simply want to verify that the text now exists as entered.

However, the results of my test (the verifyText assertion fails) suggest that the content of the $locator element are empty, even after input.

There was 1 failure:

1) test::testInput
Failed asserting that <string:> matches PCRE pattern "/Beatles/".`

Has anyone else tried anything like this? Should it work? Am I making a simple mistake?


You should use verifyValue(locator,texttoverify) rather than verifyText(locator,value) for validating the textbox values


To answer your initial question ("Is it meaningful ..."), well, maybe. What you're testing at that point is the browser's ability to respond to keystrokes, which would be sort of lame. Unless you've got some JavaScript code wired to some of the field's properties, in which case it might be sort of important.

Standard programmer's answer - "It depends".

0

精彩评论

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