title: Why am I getting AssertionError in Selenium?
body: <p>Could you advise, what can we do in the situation, when tests are running OK, but in the end of the tests there are errors and a long stack trace in Selenium?</p>
  
  <pre><code>package com.example.tests;
  
  import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.fail;
  
  import java.util.NoSuchElementException;
  import java.util.concurrent.TimeUnit;
  
  import org.junit.After;
  import org.junit.Before;
  import org.junit.Test;
  import org.openqa.selenium.Alert;
  import org.openqa.selenium.By;
  import org.openqa.selenium.NoAlertPresentException;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.chrome.ChromeDriver;
  import org.openqa.selenium.support.ui.ExpectedConditions;
  import org.openqa.selenium.support.ui.WebDriverWait;
  
  public class AddGroupTests {
    private WebDriver driver;
    private boolean acceptNextAlert = true;
    private StringBuffer verificationErrors = new StringBuffer();
  
    @Before
    public void setUp() throws Exception {
      System.setProperty("webdriver.chrome.driver","C:\\selenium-java-3.12.0\\chromedriver.exe");
      driver = new ChromeDriver();
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }
  
    @Test
    public void testAddNewGroup() throws Exception {
      openMainPage();
      findFrame();
      logIn();
      goToGroupPage();
      fillFormAndSubmit("Group1", "Head", "Foot");
      verifyTextOnPage();
      returnToGroupsPage();
    //Once all your stuff done with this frame need to switch back to default
      driver.switchTo().defaultContent();
    }
  
    @Test
    public void testAddNewEmptyGroup() throws Exception {
      openMainPage();
      findFrame();
      logIn();
      goToGroupPage();
      fillFormAndSubmit("", "", "");
      verifyTextOnPage();
      returnToGroupsPage();
    //Once all your stuff done with this frame need to switch back to default
      driver.switchTo().defaultContent();
    }
  
  private void verifyTextOnPage() {
      try {
        assertEquals("A new group has been entered into the address book.return to the group page", driver.findElement(By.xpath("//div[@id='content']/div")).getText());
      } catch (Error e) {
        verificationErrors.append(e.toString());
      }
  }
  
  private void returnToGroupsPage() {
      driver.findElement(By.linkText("group page")).click();
  }
  
  private void fillFormAndSubmit(String name, String header, String footer) {
      clickAndClear("group_name", "group_name");
      driver.findElement(By.name("group_name")).sendKeys(name);
      clickAndClear("group_header", "group_header");
      driver.findElement(By.name("group_header")).sendKeys(header);
      clickAndClear("group_footer", "group_footer");
      driver.findElement(By.name("group_footer")).sendKeys(footer);
      driver.findElement(By.name("submit")).click();
  }
  
  private void goToGroupPage() {
      driver.findElement(By.linkText("Группы")).click();
      driver.findElement(By.name("new")).click();
  }
  
  private void logIn() {
      driver.findElement(By.name("user")).clear();
      driver.findElement(By.name("user")).sendKeys("admin");
      driver.findElement(By.name("pass")).clear();
      driver.findElement(By.name("pass")).sendKeys("pass");
      driver.findElement(By.xpath("//input[@value='Войти']")).click();
  }
  
  private void findFrame() {
          WebDriverWait wait = new WebDriverWait(driver, 10);
          wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("demobody"));
  }
  
  private void openMainPage() {
      driver.get("https://www.softaculous.com/softaculous/demos/PHP_Address_Book");
  }
  
  private void clickAndClear(String locator, String locator2) {
      driver.findElement(By.name(locator)).click();
      driver.findElement(By.name(locator2)).clear();
  }
  
    @After
    public void tearDown() throws Exception {
      driver.quit();
      String verificationErrorString = verificationErrors.toString();
      if (!"".equals(verificationErrorString)) {
        fail(verificationErrorString);
      }
    }
  
    @SuppressWarnings("unused")
  private boolean isElementPresent(By by) {
      try {
        driver.findElement(by);
        return true;
      } catch (NoSuchElementException e) {
        return false;
      }
    }
  
    @SuppressWarnings("unused")
  private boolean isAlertPresent() {
      try {
        driver.switchTo().alert();
        return true;
      } catch (NoAlertPresentException e) {
        return false;
      }
    }
  
    @SuppressWarnings("unused")
  private String closeAlertAndGetItsText() {
      try {
        Alert alert = driver.switchTo().alert();
        String alertText = alert.getText();
        if (acceptNextAlert) {
          alert.accept();
        } else {
          alert.dismiss();
        }
        return alertText;
      } finally {
        acceptNextAlert = true;
      }
    }
  }
  </code></pre>
  
  <p>And the stack trace is like this:</p>
  
  <pre><code>java.lang.AssertionError: org.junit.ComparisonFailure: expected:&lt;...to the address book.[]return to the group ...&gt; but was:&lt;...to the address book.[
  ]return to the group ...&gt;
      at org.junit.Assert.fail(Assert.java:88)
      at com.example.tests.AddGroupTests.tearDown(AddGroupTests.java:112)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.base/java.lang.reflect.Method.invoke(Unknown Source)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
      at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:42)
      at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)
      at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
      at java.base/java.util.Iterator.forEachRemaining(Unknown Source)
      at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source)
      at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
      at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
      at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
      at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
      at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
      at java.base/java.util.stream.ReferencePipeline.forEach(Unknown Source)
      at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:83)
      at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:74)
      at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
      at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
      at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
      at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:86)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
  </code></pre>
  
  <p>Tried to erase all imports and to fix red problem one by one, still, failures exist. I see the message: AssertionError, but unable to locate the problem. Any suggestions? Thanks in advance</p>