It Is really Importnt to find Javascript errors on spider web page earlier whatever application's release. Generally Test engineer Goes to each together with every page manually together with banking concern tally If in that place Is whatever coffee script fault on page. It tin direct maintain really much time. We tin automate this task using selenium webdriver Instead of doing It manually.
How to Find JS errors using selenium webdriver
Selenium WebDriver practise non direct maintain whatever built In method or constituent using which nosotros tin collect JS errors from page. For that you lot demand to download "JSErrorCollector-0.5.jar" file from THIS PAGE together with Include It In your project's construct path. You tin refer "Adding jounce Files In Project's Build Path" department on THIS PAGE If you lot don't know how to add together It.
Now you lot tin practise bellow given event In your eclipse. I direct maintain used page alongside javascript error.
package Testing_Pack; import java.util.List; import java.util.concurrent.TimeUnit; import net.jsourcerer.webdriver.jserrorcollector.JavaScriptError; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; populace degree jsError { WebDriver driver; @BeforeTest populace void setup() throws Exception { FirefoxProfile profile = novel FirefoxProfile(); JavaScriptError.addExtension(profile); driver = novel FirefoxDriver(profile); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get(" "); } @Test populace void printPageErrors() throws Exception { //Capture all errors together with shop them In array. List<JavaScriptError> Errors = JavaScriptError.readErrors(driver); System.out.println("Total No Of JavaScript Errors : " + Errors.size()); //Print Javascript Errors i past times i from array. for (int i = 0; i < Errors.size(); i++) { System.out.println("Error Message : " + Errors.get(i).getErrorMessage()); System.out.println("Error Line No : " + Errors.get(i).getLineNumber()); System.out.println(Errors.get(i).getSourceName()); System.out.println(); } } }
Check the console output on examination completion. It volition impress JSError equally bellow In console.
Error Message : ReferenceError: adddlert is non defined Error Line No : 729
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM
http://www.software-testing-tutorials-automation.com/