Hide com.gargoylesoftware.htmlunit.. Warnings Logs From Console In WebDriver

In previous postal service nosotros learnt how to run your selenium test In HTML Unit driver or headless browser. If you lot are using HtmlUnit Driver to run your test, Sometimes you lot volition run across lots of warnings equally a log alongside text similar "com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error". This Is
one form of alert in addition to nosotros tin eliminate It really easily.

We tin use Java Logging API to eliminate this alert message from console. Main usage of this JAVA API Is to write execution log, reporting errors in addition to warnings. You tin gear upward dissimilar levels of log based on your requirement. Here nosotros volition plough that log score to OFF using bellow given syntax.

//To enshroud warnings logs from execution console. Logger logger = Logger.getLogger(""); logger.setLevel(Level.OFF);

Full selenium Html Unitdriver  test example to enshroud alert logs from execution console Is equally bellow.
package Testing_Pack;  import java.util.List; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  world shape htmlDriver {    HtmlUnitDriver driver;  String pagetitle;   @BeforeTest  world void setup() throws Exception {   //Initializing HtmlUnitDriver.   driver = novel HtmlUnitDriver();   driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);      //To enshroud warnings logs from execution console.   Logger logger = Logger.getLogger("");   logger.setLevel(Level.OFF);      //Opening URL In HtmlUnitDriver.   driver.get("http://www.google.com");  }   @AfterTest  world void tearDown() throws Exception {   //Closing HtmlUnitDriver.   driver.quit();  }   @Test  world void googleSearch() {      //Get in addition to impress page championship earlier search.   pagetitle = driver.getTitle();   System.out.println("Page championship earlier search : "+pagetitle);      //Search alongside Hello World on google.   WebElement Searchbox = driver.findElement(By.xpath("//input[@name='q']"));   Searchbox.sendKeys("Hello World");   Searchbox.submit();      //Get in addition to impress page championship later search.   pagetitle = driver.getTitle();   System.out.println("Page championship later search : "+pagetitle);      //Get listing of search upshot strings.   List<WebElement> allSearchResults=driver.findElements(By.cssSelector("ol li h3>a"));    //Iterate the inwards a higher house listing to acquire all the search titles & links from that page.   for(WebElement eachResult : allSearchResults) {   System.out.println("Title : "+eachResult.getText()+", Link : "+eachResult.getAttribute("href"));   }  } }

Now you lot volition non run across whatever "com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error" log messages. This Is the agency to eliminate whatever unwanted warnings from console. Next postal service volition nation you lot how to execute javascript In HTMLUnit driver test.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post