2011-06-04 93 views
0

你好,我是用硒下面的测试,但我在运行该程序的错误:Asse田空Selenium测试

public class TestExemplo extends SeleneseTestNgHelper { 
    @Test public void testUntitled() throws Exception { 
     selenium.open("http://gmail.com"); 
     selenium.type("Email", "edipofederle"); 
     selenium.type("Passwd", "pass"); 
     selenium.click("signIn"); 
     selenium.waitForPageToLoad("30000"); 
     assertTrue(selenium.isTextPresent("You are currently")); 
    } 
} 

java.lang.AssertionError: null 
    at com.thoughtworks.selenium.SeleneseTestBase.fail(SeleneseTestBase.java:372) 
    at com.thoughtworks.selenium.SeleneseTestBase.assertTrue(SeleneseTestBase.java:377) 
    at com.thoughtworks.selenium.SeleneseTestBase.assertTrue(SeleneseTestBase.java:381) 
    at com.example.tests.TestExemplo.testUntitled(TestExemplo.java:15) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 

有人能帮助我吗?谢谢..

+0

有什么问题吗?它看起来像断言失败,因为文本不存在于该页面? – 2011-06-04 17:11:22

+0

是的,这是看起来像,但文本存在...我登录Gmail后.. – elf 2011-06-04 17:15:55

+0

显然问题发生后,我已经登录到Gmail,因为在首页断言发生成功... – elf 2011-06-04 17:29:34

回答

0

的问题是,你的硒司机认为文本不存在,因此是返回false。你的主张因此而失败。

可以检查getHtmlSource方法的输出是什么样子?可粘贴到此处,使得文本(或不存在)的存在可能是

+0

HI Pavan,这里的html为getHtmlsource https://gist.github.com/1008339 – elf 2011-06-04 20:43:16

+0

在日志eclipse中默认测试 测试运行:1,失败:0,跳过:0 配置失败:1,跳过:0 – elf 2011-06-04 21:17:48

+0

嗨,我注意:任何应用程序,然后我登录需要断言不做工精细,为为例,Gmail的初始页面(登录前)断言工作非常好,但登录后没有。这对于任何应用程序......我没有想法,为什么出现这种情况?谢谢 – elf 2011-06-04 23:16:59

1

这可能是因为你检查的页面后,加载由JavaScript文本已经加载。这意味着在调用assertTrue()时,文本还没有出现。你既可以尝试waitForCondition()或只是一个普通的Thread.sleep()使得文本有机会assertTrue()运行之前填充。

+0

您好,我尝试这样做,但不要工作太,我是尝试的Watir就此别过,但具有相同的probleam,登录后,我有例如,通过xpath的文本错误...使用线程睡眠太.... – elf 2011-06-05 03:12:01