嗨,我正在尝试测试编辑文本,放置两个不同的值,但是第二个测试失败了,.reasons unknown...below是我的代码TestCase1。
public void testvalues1() {
// clearing the edit text
mTextView.clearComposingText();
TouchUtils.tapView(this, mTextView);
// sending input as 7
sendKeys("7");
String userInput1;
String expected = "158269.3778";
String parameterFrom1 = "0.0027";
String parameterTo1 = "61.04676";
// getting the input from the mTextView reference
userInput1 = mTextView.getText().toString();
String resultset = UnitCalculation.Converter(parameterFrom1,userInput1,parameterTo1);
assertEquals(resultset, expected);
}在上面的测试用例中,iam发送值7和输出与预期相同。
TestCase2
public void testvalues2() {
// clearing the edit text
mTextView.clearComposingText();
TouchUtils.tapView(this, mTextView);
// sending input as 23
sendKeys("23");
String userInput1;
String expected = "150.5011";
String parameterFrom1 = "1.092607";
String parameterTo1 = "7.149502";
// getting the input from the mTextView reference
userInput1 = mTextView.getText().toString();
String resultset1 = UnitCalculation.Converter(parameterFrom1,userInput1,parameterTo1);
System.out.println("printing resilt set "+ resultset1);
assertEquals(resultset1, expected);
}但是该方法返回的值为0,而不是使用相同的方法计算的150.5011 Iam,当我给出像这个字符串userInput1=“23”这样的硬编码的用户值时;是工作的,但是当从编辑文本中获取值时,它是无效的。
我可以发送多个值来编辑同一个测试文件上的文本吗??
发布于 2014-11-26 09:24:35
有多个字符的sendKeys是搞砸它的原因。见本参考。
总之,sendKeys需要一个包含空格分隔键的字符串。您的sendKeys("23")正在尝试在名为23的软键盘中找到一个键,尽管没有。
sendKeys("2 3");因为它将分别发送这两个键笔画,而不是试图找到一个名为23的键。这就是为什么只发送一个7的原因,因为7是"7“的关键名称。
https://stackoverflow.com/questions/27144709
复制相似问题