title: TestNG - set a "global" variable so that certain tests will always fail
body: <p>I'm writing Selenium UI tests for my e-commerce company.  We use a test company credit card that (unfortunately) has a credit ceiling.  Occasionally the credit ceiling will be reached during testing, the "user" will be given an Auth denied message, and the test will fail. I want to set a flag somewhere that, when set to true, will result in all tests using the fake credit card will fail automatically.  </p>
  
  <p>Here is a basic setup of my code:</p>
  
  <p><strong>Base.java</strong></p>
  
  <pre><code>public class Base 
  {    
      public WebDriver driver = null;     
      public WebDriver getDriver() 
      {
          return new ChromeDriver();
      }    
  }
  </code></pre>
  
  <p><strong>Page.java</strong></p>
  
  <pre><code>public class Page extends Base 
  {
      By ccField;
      By successElement;
  
      public Page(WebDriver driver) 
      {
          this.driver = driver;
          ccField = By.id("ccField");
          successElement = By.id("success");
      }
  
      public boolean sendCreditCard(String num) 
      {
          driver.findElement(ccField).sendKeys(num);
          return driver.findElement(successElement).isDisplayed();
      }
  
  }
  </code></pre>
  
  <p><strong>TestBase.java</strong></p>
  
  <pre><code>public class TestBase extends Base 
  {    
      @BeforeMethod
      public void setup() 
      {
          Base b = new Base();
          driver = b.getDriver();
      }
  
      @AfterMethod
      public void tearDown() 
      {
          driver.quit();
      }   
  }
  </code></pre>
  
  <p><strong>PageTests.java</strong></p>
  
  <pre><code>public class PageTests extends TestBase 
  {   
      Page page;
      boolean failedBecauseOfAuth = false;
  
      @BeforeMethod
      public void setup() 
      {
          page = new Page(driver);
      }
  
      @Test
      public void one() 
      {
          // Single ship (for example)
          boolean success = page.sendCreditCard("5555555555555555");
          Assert.assertTrue(success);
      }
  
      @Test
      public void two() 
      {
          // Multi ship (for example)
          boolean success = page.sendCreditCard("5555555555555555");
          Assert.assertTrue(success);
      }
  
  }
  </code></pre>
  
  <p>Essentially, if <code>one</code> failed because of an auth denied error, I need <code>two</code> to automatically fail at the beginning of the test. The problem is, every-time I set a flag (like <code>authFailed = false</code> as a field of <code>PageTests.java</code>, and then set <code>authFailed = true</code> when needed) it gets reset at the beginning of the next test run.</p>