【发布时间】:2011-06-28 16:19:55
【问题描述】:
我有一个非常简单的 selenium 脚本来尝试调试我遇到的问题。我所做的就是填写用户名,然后填写密码,然后检查我输入的密码是否在密码字段中。我这样做的原因是我通常无法对其进行身份验证,当它是正确的密码时,总是会出现“密码错误问题”。
表单html:
<input class="inp" id="userName" name="userName" type="text" />
<input class="inp" id="password" name="password" type="password" />
<label for="rememberMe">remember</label>
<input class="rem" id="rememberMe" name="rememberMe" type="checkbox" value="true" />
<input name="submit" id="loginSubmit" value="go" type="image" src="http://terra/wp-content/themes/ecobee/images/arrow-right_16x16.gif" />
还有从我的 Selenium 脚本创建的 Java:
package com.example.tests;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;
public class toso extends SeleneseTestCase {
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://terra/");
selenium.start();
}
@Test
public void testToso() throws Exception {
selenium.open("/");
selenium.type("userName", "cw@qa.com");
selenium.type("password", "qqqqqqqq");
verifyEquals("qqqqqqqq", selenium.getValue("password"));
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}
这会抛出一个expected "" to match glob "qqqqqqqq" (had transformed the glob into regexp "qqqqqqqq"),提示填写密码字段。我还观察了在慢速模式下完成的测试,脚本填写了用户名,但没有填写密码字段。
【问题讨论】:
-
您是否尝试过为密码字段使用不同的描述符?
-
@rs79 是的,我已经想到了,但是描述符正在工作。我在上面的测试中添加了
selenium.highlight("password"),它突出显示了正确的气泡。您认为这仍然是问题所在? -
我建议为 selenium.getValue(...) 中的密码字段尝试 css 标识符;
-
@rs79 这能解释为什么当我看到代码执行时,密码字段中没有文本吗?
-
我尝试了您的代码,但最终没有发现任何问题。我会尝试的另一件事可能是降低执行速度