Page tree
Skip to end of metadata
Go to start of metadata

If you're running pipeline tests, read the next section: Selenium Pipeline Tests too. NRG_Selenium is built around testNG (previously JUnit), to make use of TestListeners and testing annotations to finely tune when different setup and test handling needs to occur. To get the most out of the NRG_Selenium framework, you should format your tests to extend the classes provided. More specifically, all test classes created in your project should extend BaseTestCase. By doing this, your test suite automatically has access to the methods annotated with the testNG annotation @BeforeSuite, which will:

  1. Perform a sanity check and make sure you have reasonable settings defined.
  2. Set up REST Assured.
  3. If JIRA integration is turned on, create a test execution cycle with all tests to be run listed in Unexecuted status. Read more here: JIRA Zephyr & ZAPI Integration.
  4. If xnat.init is true, initialize non-admin and admin selenium accounts according to passed properties.
  5. Download all of the required test data from the NRG FTP Site, as described by the @TestRequires annotations (read more: Annotation-Based Requirements).

Since the @BeforeSuite annotation is used, all of these steps will only be performed a single time upon initialization. Secondly, the methods with the @BeforeClass annotation will execute, which:

  1. Parses the @TestRequires annotations on the tests/class and checks for certain prerequisites and performs some actions, as described in Annotation-Based Requirements.

Also, the methods with the @BeforeMethod annotation will run before every test begins. This process includes:

  1. Creating a new WebDriver instance to power the tests, along with seleniumUtils and xnatUtils objects to provide convenience methods.
  2. If JIRA integration is turned on, initializes the step counter and prepares the JIRA test execution.
  3. Checks test-level requirements from Annotation-Based Requirements.

Finally, by extending BaseTestCase, you also get automatic integration with NRG_Selenium's TestListener. This listener automatically:

  1. Prints messages at various times during tests with updates (when test begins, fails, is skipped, or passes).
  2. If JIRA integration is turned on, sets test execution to WIP (Work in Progress) when test starts, and appropriately updates the test when test fails, passes, or is skipped.
  3. Shuts down the Selenium WebDriver object.

I've mentioned things like "your tests" so far, but how does the framework know what a test is? Put simply, any method annotated with testNG's @Test annotation is treated as a discrete test for all the purposes listed above. When using this annotation, a "failure" entails any exception thrown before the method completes, mostly commonly java.lang.AssertionError (wrong values) or org.openqa.selenium.NoSuchElementException (required element not found on the page). A "pass" occurs when the end of the test method is reached without Exception, or equivalently when the method returns early.

  • No labels