title: Selenium WebDriver - two part - 1) Fail test on AssertEquals failure 2)Verify Element not present
body: <p>I am back with more silly questions </p>
  
  <p>1) How to fail a test if AssertEquals is false?</p>
  
  <p>I have this code -</p>
  
  <pre><code>public boolean compareWidthPixels(By by, String expected) {
      System.out.println(driver.findElement(by).getCssValue("width"));
      try {
          assertEquals(expected, driver.findElement(by).getCssValue("width"));
          System.out.println("Width as expected");
          return true;
  
      } catch (Error e) {
          verificationErrors.append(e.toString());
          System.out.println("Width incorrect");
          return false;
  
      }
  </code></pre>
  
  <p>This code displays "Width incorrect" when the width does not match the expected value but the test case passes. I want the test to fail if the width are unequal. </p>
  
  <p>2) How to assert/verify an Element is NOT present?</p>
  
  <p>As a novice I tried many  things I found in Google and here in Stack Overflow -
  <a href="https://stackoverflow.com/questions/3283310/assert-that-a-webelement-is-not-present">Assert that a WebElement is not present using Selenium WebDriver with java</a>, <a href="https://stackoverflow.com/questions/7991522/selenium-webdriver-test-if-element-is-present">Selenium WebDriver - Test if element is present</a>, etc. But none of them worked. I am working with JUnit4 and need a function that should pass if the element is not present. </p>
  
  <p>Thanks</p>
  
  <p>Maitreya</p>
  
  <p>P.S: Please feel free edit this question if it looks confusing or disoriented. </p>