Quantcast
Channel: Intense Testing » Software Testiing
Viewing all articles
Browse latest Browse all 5

Find out JS Error on Firefox using Selenium Webdriver

0
0
We need to add a JSERROR Collector jar to our project.
We need to add the below dependency to the POM to download the jar file: -
<dependency>
<groupId>net.jsourcerer.webdriver</groupId>
<artifactId>JSErrorCollector</artifactId>
<version>0.5-atlassian-2</version>
</dependency>

Also we need to add a firefox addon to firefox profile which we will be using to automate. Click to Download
Below is the sample code to find out the js errors on a page: -

public class jserrorcollection
{
public static WebDriver wbdv = null;
public static EventFiringWebDriver driver=null;
@BeforeClass
public static void setUp() throws IOException {
System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
try
{
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("default");
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
wbdv = new FirefoxDriver(profile);
driver = new EventFiringWebDriver(wbdv);
}catch(Throwable t)
{
System.out.println(t);
}driver.get("http://useyoururl.com");
}
@AfterClass
public static void tearDown() {
List<JavaScriptError> jsErrors = JavaScriptError.readErrors(driver);
System.out.println("###start displaying errors");
for(int i = 0; i < jsErrors.size(); i++)
{
System.out.println(jsErrors.get(i).getErrorMessage());
System.out.println(jsErrors.get(i).getLineNumber());
System.out.println(jsErrors.get(i).getSourceName());
}
System.out.println("###start displaying errors");
driver.close(); driver.quit();
}
@Test
public void returnJavascriptErrors() throws InterruptedException {
Thread.sleep(5000);
}
}

Written By: Priyadarshan Mohanty, QA Team Lead, Mindfire Solutions



Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images