Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #446 from Magenic/JMAQS-430
Browse files Browse the repository at this point in the history
Stack Overflow Fix
  • Loading branch information
jason-edstrom authored Nov 30, 2020
2 parents 766ed77 + 25aa1e9 commit 6f28ace
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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" } };
}

/**
Expand Down
2 changes: 1 addition & 1 deletion maqs_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<property name="caseIndent" value="2"/>
</module>
<module name="AbbreviationAsWordInName">
<property name="allowedAbbreviationLength" value="3"/>
<property name="allowedAbbreviationLength" value="5"/>
<property name="ignoreFinal" value="false"/>
</module>
<module name="OverloadMethodsDeclarationOrder"/>
Expand Down

0 comments on commit 6f28ace

Please sign in to comment.