I have a selenium script and I need to write the failures to a log file. For example if a page is not found or selenium.waitForPageToLoad expires. Instead of going straight to tearDown(), I would like to log why my script has stopped.
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();
Also would it be possible to skip a steap if it fails, right now if anything at all fails it will go straight to the teardown() method.
I am using java.
What you are asking is exception handling. If any of the steps in your tests fails then selenium will throw an exception and tests would stop. If you handle the exceptions using
try catchthen you should be able to achieve what you are looking for. As an example, see the code below. This would handle the initial page load timeout. Even ifselenium.openfails, script will handle the exception and move ahead to next statement. You should read more about exception handling to find what is the best way to handle these exceptions.