diff --git a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/exceptions/JMAQSRuntimeException.java b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/exceptions/JMAQSRuntimeException.java new file mode 100644 index 000000000..9ce93cbc8 --- /dev/null +++ b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/exceptions/JMAQSRuntimeException.java @@ -0,0 +1,17 @@ +/* + * Copyright 2020 (C) Magenic, All rights Reserved + */ + +package com.magenic.jmaqs.base.exceptions; + +public class JMAQSRuntimeException extends RuntimeException { + + public JMAQSRuntimeException(String message, Exception exception) { + super(message, exception); + } + + public JMAQSRuntimeException(String message) { + super(message); + } +} + diff --git a/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/BaseSeleniumTest.java b/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/BaseSeleniumTest.java index 440d47b22..5b4379ed1 100644 --- a/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/BaseSeleniumTest.java +++ b/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/BaseSeleniumTest.java @@ -37,9 +37,8 @@ public WebDriver getWebDriver() { * Sets web driver. * * @param webDriver the web driver - * @throws Exception exception */ - public void setWebDriver(WebDriver webDriver) throws Exception { + public void setWebDriver(WebDriver webDriver) { this.getTestObject().setWebDriver(webDriver); } @@ -81,11 +80,12 @@ protected void createNewTestObject() { return getBrowser(); } catch (WebDriverFactoryException e) { getLogger().logMessage(StringProcessor.safeFormatter("Failed setup driver: %s", e.toString())); + throw e; } - return null; }, this.createLogger(), this.getFullyQualifiedTestClassName())); } catch (Exception e) { getLogger().logMessage(StringProcessor.safeFormatter("Test Object could not be created: %s", e.getMessage())); + throw e; } } } \ No newline at end of file diff --git a/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/SeleniumTestObject.java b/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/SeleniumTestObject.java index 61106afe5..90f057e7c 100644 --- a/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/SeleniumTestObject.java +++ b/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/SeleniumTestObject.java @@ -5,7 +5,9 @@ package com.magenic.jmaqs.selenium; import com.magenic.jmaqs.base.BaseTestObject; +import com.magenic.jmaqs.base.exceptions.JMAQSRuntimeException; import com.magenic.jmaqs.utilities.logging.Logger; +import com.magenic.jmaqs.utilities.logging.MessageType; import java.util.function.Supplier; import org.openqa.selenium.WebDriver; @@ -64,12 +66,18 @@ public SeleniumDriverManager getWebManager() { * @param driver the driver * @throws Exception exception */ - public void setWebDriver(WebDriver driver) throws Exception { + public void setWebDriver(WebDriver driver) { String name = SeleniumDriverManager.class.getCanonicalName(); if (this.getManagerStore().containsKey(name)) { - this.getManagerStore().get(name).close(); - this.getManagerStore().remove(name); + try { + this.getManagerStore().get(name).close(); + this.getManagerStore().remove(name); + } catch (Exception e) { + getLogger().logMessage(MessageType.ERROR, "Failed to remove DriverManager: %s", e.getMessage()); + throw new JMAQSRuntimeException(e.getMessage(), e); + } + } this.getManagerStore().put(name, new SeleniumDriverManager((() -> driver), this)); diff --git a/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/exceptions/DriverNotFoundException.java b/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/exceptions/DriverNotFoundException.java index 4364fd2e9..6af4689e6 100644 --- a/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/exceptions/DriverNotFoundException.java +++ b/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/exceptions/DriverNotFoundException.java @@ -4,10 +4,21 @@ package com.magenic.jmaqs.selenium.exceptions; +import com.magenic.jmaqs.base.exceptions.JMAQSRuntimeException; + /** * The type Driver not found exception. */ -public class DriverNotFoundException extends RuntimeException { +public class DriverNotFoundException extends JMAQSRuntimeException { + /** + * Instantiates a new Driver not found exception. + * + * @param message the message + */ + public DriverNotFoundException(String message, Exception exception) { + super(message, exception); + } + /** * Instantiates a new Driver not found exception. * diff --git a/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/exceptions/ElementHandlerException.java b/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/exceptions/ElementHandlerException.java index 50b9a6c91..78885f398 100644 --- a/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/exceptions/ElementHandlerException.java +++ b/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/exceptions/ElementHandlerException.java @@ -4,10 +4,12 @@ package com.magenic.jmaqs.selenium.exceptions; +import com.magenic.jmaqs.base.exceptions.JMAQSRuntimeException; + /** * The type Element handler exception. */ -public class ElementHandlerException extends RuntimeException { +public class ElementHandlerException extends JMAQSRuntimeException { private static final long serialVersionUID = 1; @@ -19,4 +21,17 @@ public class ElementHandlerException extends RuntimeException { public ElementHandlerException(String message) { super(message); } + + /** + * Instantiates a new Element handler exception. + * + * @param message the message + * @param exception the exception + */ + public ElementHandlerException(String message, Exception exception) { + super(message, exception); + } + + + } diff --git a/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/exceptions/WebDriverFactoryException.java b/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/exceptions/WebDriverFactoryException.java index 81478833d..0140a9f50 100644 --- a/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/exceptions/WebDriverFactoryException.java +++ b/jmaqs-selenium/src/main/java/com/magenic/jmaqs/selenium/exceptions/WebDriverFactoryException.java @@ -4,10 +4,12 @@ package com.magenic.jmaqs.selenium.exceptions; +import com.magenic.jmaqs.base.exceptions.JMAQSRuntimeException; + /** * The type Web driver factory exception. */ -public class WebDriverFactoryException extends RuntimeException { +public class WebDriverFactoryException extends JMAQSRuntimeException { /** * Instantiates a new Web driver factory exception. diff --git a/jmaqs-selenium/src/test/java/com/magenic/jmaqs/selenium/BaseSeleniumTestUnitTest.java b/jmaqs-selenium/src/test/java/com/magenic/jmaqs/selenium/BaseSeleniumTestUnitTest.java index 555d70975..61bc056cb 100644 --- a/jmaqs-selenium/src/test/java/com/magenic/jmaqs/selenium/BaseSeleniumTestUnitTest.java +++ b/jmaqs-selenium/src/test/java/com/magenic/jmaqs/selenium/BaseSeleniumTestUnitTest.java @@ -5,7 +5,6 @@ package com.magenic.jmaqs.selenium; import com.magenic.jmaqs.utilities.helper.TestCategories; - import org.openqa.selenium.WebDriver; import org.testng.Assert; import org.testng.annotations.DataProvider; @@ -35,8 +34,8 @@ public void testSetWebDriver() { @Test(groups = TestCategories.SELENIUM) public void testGetSeleniumTestObject() { - Assert.assertNotNull(this.getTestObject(), - "Checking that Selenium Test Object is not null through BaseSeleniumTest"); + Assert + .assertNotNull(this.getTestObject(), "Checking that Selenium Test Object is not null through BaseSeleniumTest"); } @Test(groups = TestCategories.SELENIUM) @@ -46,8 +45,7 @@ public void testGetBrowser() { try { driver = this.getBrowser(); - Assert.assertNotNull(driver, - "Checking that Selenium Driver is not null through BaseSeleniumTest"); + Assert.assertNotNull(driver, "Checking that Selenium Driver is not null through BaseSeleniumTest"); } catch (Exception e) { e.printStackTrace(); } finally { @@ -57,11 +55,7 @@ public void testGetBrowser() { @DataProvider(name = "data") public Object[][] getData() { - return new Object[][]{ - {"First"}, - {"Second"}, - {"Third"} - }; + return new Object[][] { { "First" }, { "Second" }, { "Third" } }; } /** diff --git a/maqs_checks.xml b/maqs_checks.xml index 4e8df1ce3..b2ae063a0 100644 --- a/maqs_checks.xml +++ b/maqs_checks.xml @@ -118,7 +118,7 @@ - +