title: Where should my Selenium tests check for expected/actual results?
body: <p>I am currently designing a testing framework for a web application. The framework is a hybrid (data and keyword driven) framework. I have it set up so I have packages full of UI functions who's methods I can call into test classes to navigate and click the application.</p>
  
  <p>I'm wondering about best practices.</p>
  
  <p>Should I be checking for results with every step I take? Or should I check results at the end of the test?</p>
  
  <p>For more detail, this is the current structure of my test with minimized code:</p>
  
  <pre><code>// This test contains one step. The following method navigates to the page and inputs invalid credentials.
  // We than check if we're still on the login page. If we are, the test passes. If we can't find the
  // "login text", than the test has failed.
          LoginPage.invalidCredentialsOne.run(driver);
          Thread.sleep(2000);
  
          WebElement logintext = driver.findElement(By.xpath(prop.getProperty("logintext")));
          if (logintext.getText().equals("LOG IN")) {
              //add pass entry to the excel sheet
              testresultdata.put("3", new Object[] {
                  2d, "User should not be able to login with an invalid password", "Login failed", "Pass"
              });
              driver.close();
              Alert alert = driver.switchTo().alert();
              alert.accept();
          } else {
              //add fail entry to the excel sheet
              testresultdata.put("3", new Object[] {
                  2d, "User should not be able to login with an invalid password", "Login failed", "Fail"
              });
              fail();
              driver.close();
              Alert alert = driver.switchTo().alert();
              alert.accept();
          }
  </code></pre>
  
  <p>In the above code, I check for expected/actual results <em>AFTER</em> I have ran the method. Would it be advisable to check the expected/actual results inside the method itself? What would the pros/cons of this be?</p>
  
  <p>I feel as though running the expected/actual results in the method would improve maintainability as well as test accuracy (being able to see exactly where your test failed).</p>
  
  <p>Or why not just test through both?</p>
  
  <p>Methods - Check every navigation made. If the navigation failed, output a line in the console telling you where. This checks for simple UI bugs.</p>
  
  <p>Test classes - Check for more specific user scenarios.</p>
  
  <p>Very interested in the proper best practices to do this. Thanks in advance.</p>