Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Selenium WebDriver to report Javascript errors

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Almost all websites use some level of Javascript to perform certain operations on UI. During manual testing, when using the chrome browser, we can check for Javascript errors by checking the console of the developer tool.

To report Javascript errors using Selenium WebDriver, we need to add JSERROR Collector jar to the project by adding the following dependencies to the POM file:

Net.jsourcerer.webdriver

JSErrorCollector

0.5-atlassian-2

We also need to add a firefox plug-in to the firefox configuration file in the settings of the automated test so that we can catch Javascript errors in Selenium WebDriver. Click to download the firefox plug-in.

Here is a sample WebDriver code that uses the above library and firefox plug-in to report Javascript errors:

Public class JSErrorTest {

Public static WebDriver wbdv = null;public static EventFiringWebDriver driver=null;@BeforeClasspublic 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://www.example.com");}@AfterClasspublic static void tearDown () {List jsErrors = JavaScriptError.readErrors (driver); System.out.println (" # start displaying errors "); for (int I = 0; I < jsErrors.size () ) {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 ();} @ Testpublic void returnJavascriptErrors () throws InterruptedException {/ / do your steps}

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report