Selenide usage simple notes: IE, TestNG, Bootstrap dropdown

Selenide usage simple notes: IE, TestNG, Bootstrap dropdown

IE, One way to add Selenide screenshot into the TestNG HTML reporter, One way to work with customized Bootstrap HTML elements


My name is Sergey Shimkiv. Below you can find some notes about Selenide/Selenium usage.

IE notes

IE 11 x32/x64. In some cases after the actions with HTML elements (click() for example) you can receive an exception.
The cause of it could be synthetic events usage. The workaround is to use native events for IE:

   capabilities.setCapability("nativeEvents", "true");

One way to add Selenide screenshot into the TestNG HTML reporter

In some cases you might want to add Selenide’s screenshots of failed tests into your TestNG HTML reporter.

For example: You write two tests (Test1 and Test2) which must be linked (Test2 depends on Test1 results). But you know that Test1 will fail because of application bug(s). So you will write something like this:

   public void Test1() {
    try {
      // Test block with known bug
    } catch(...) {
      // Some actions
    } finally {
      // You want to perform some actions here to ensure correct preconditions for the Test2

Let’s assume that you’re using own test listener that extends TestListenerAdapter. And you have overridden onTestFailure(ITestResult result) method to collect some additional information into the HTML report - your own screenshots for example. In such case it is possible that your screenshot gathering implementation will collect incorrect data because finally block can be performed before screenshot will be taken.

Just keep in mind that Selenide’s screenshot file name (that will be taken directly after some exception) could be taken from result.getThrowable().getMessage();

One way to work with customized Bootstrap HTML elements

Tests often get complicated when you need to test customized HTML controls with complex logic.

For example, Bootstrap’s dropdown elements are represented via set of HTML elements. In common:

  <div class="dropdown">
    <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
      <span class="caret"></span>
    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
      <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
      <li role="presentation" class="divider"></li>
      <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>

The problem is that the <ul> element initially is not visible for the Selenium (and for Selenide too). To be able to select some dropdown element value you can:

   SelenideElement parentDiv = $(".dropdown");
   // Find `<button>` element and `click()` on it
   // Now you can find needed dropdown element value by text

In the next post I would like to share experience in the automated testing environment deployment (based on Grid2).

Thanks to the Selenide’s authors for their great tool ;)

Sergey Shimkiv