我有一个非常简单的脚本,用于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"),提示填写了密码字段。我还观察了在慢速模式下完成的测试,脚本填写了用户名,但没有填写密码字段。
发布于 2011-06-29 03:34:41
非常奇怪,从来没有真正发现为什么这个方法不适用于这个特定的字段,它可以在页面上的其他地方工作。
我解决这个问题的方法是
char[] password = {'p','a','s','s','w','o','r','d'};
for(int i = 0; i < 8; i++){
selenium.keyPress("password", password[i]);
}https://stackoverflow.com/questions/6509719
复制相似问题