From ac66d6f1b3c3a867de23833273eb08445c31423f Mon Sep 17 00:00:00 2001 From: dylanlacey Date: Mon, 5 Nov 2018 13:41:26 +1000 Subject: [PATCH] Add a check for missing credentials. Missing environment variables cause tests to fail to start on the Sauce Labs end. This change adds an assertion for both credential values, checking their respective environment variables and raising an error if they are not set. --- src/test/java/com/yourcompany/Tests/TestBase.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/com/yourcompany/Tests/TestBase.java b/src/test/java/com/yourcompany/Tests/TestBase.java index ffb5b64..13d5932 100644 --- a/src/test/java/com/yourcompany/Tests/TestBase.java +++ b/src/test/java/com/yourcompany/Tests/TestBase.java @@ -10,9 +10,11 @@ import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.ITestResult; +import org.testng.annotations.BeforeSuite; import org.testng.annotations.AfterMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Listeners; +import org.testng.Assert; import java.lang.reflect.Method; import java.net.MalformedURLException; @@ -42,6 +44,13 @@ public class TestBase { */ private ThreadLocal sessionId = new ThreadLocal(); + /** Checks that authentication credentials have been set */ + @BeforeSuite + private void checkForCredentials(){ + Assert.assertNotNull(username, "The SAUCE_USERNAME environment variable must be set."); + Assert.assertNotNull(accesskey, "The SAUCE_ACCESS_KEY environment variable must be set."); + } + /** * DataProvider that explicitly sets the browser combinations to be used. *