2011-07-05 91 views
0

我有一个硒脚本,我需要将故障写入日志文件。例如,如果找不到页面或者selenium.waitForPageToLoad过期。我不想直接去tearDown(),我想记录为什么我的脚本已经停止。将硒错误写入日志文件并处理错误

selenium.open("/confluence/login.action?logout=true"); 
    selenium.type("os_username", "login"); 
    selenium.type("os_password", "pw"); 
    selenium.click("loginButton"); 

    selenium.waitForPageToLoad("10000");  
    selenium.click("title-heading"); 
    selenium.click("spacelink-INTR"); 
    selenium.waitForPageToLoad("10000"); 
    selenium.click("link=Create Issue Links"); 
    selenium.waitForPageToLoad("10000"); 
    selenium.click("quick-search-query"); 
    selenium.type("quick-search-query", "create issue links"); 
    selenium.click("quick-search-submit"); 
    selenium.waitForPageToLoad("100000"); 
    stoptime = System.currentTimeMillis(); 

也才有可能跳过STEAP如果失败的话,现在如果在所有出现任何故障,它会直接进入拆解()方法。 我正在使用java。

回答

0

你在问什么是异常处理。如果测试中的任何步骤都失败,则硒会抛出异常并停止测试。如果您使用try catch来处理例外情况,那么您应该能够实现您正在寻找的内容。作为一个例子,请看下面的代码。这将处理初始页面加载超时。即使selenium.open失败,脚本也会处理该异常并转到下一个语句。您应该阅读更多关于异常处理的知识,以找出处理这些异常的最佳方法。

try{ 
selenium.open("/confluence/login.action?logout=true"); 
} 
catch(Exception e) 
{ 
//Code to write data to a file goes here 
System.out.println("Selenium open did not work") 
}