This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dougnoel.sentinel.enums; | |
/** | |
* Possible methods for an API to authenticate. | |
* | |
* @author Doug Noël | |
* | |
*/ | |
public enum AuthenticationType { | |
NONE, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets a JWT Token from a currently open browser that you have logged into | |
* and sets it for the curently active API | |
*/ | |
@When("^I scrape the JWT from the current page$") | |
public void scrapeJWT() { | |
AuthenticationType authType = AuthenticationType.JWT; | |
APIManager.getAPI().setAuthType(authType); | |
APIManager.getAPI().setAuthToken(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private AuthenticationType authenticationType = NONE; | |
private Object authToken = null; | |
private static final AuthenticationType JWT = AuthenticationType.JWT; | |
private static final AuthenticationType AUTH_KEY = AuthenticationType.AUTH_KEY; | |
private static final AuthenticationType NONE = AuthenticationType.NONE; | |
/** | |
* Sets the authentication type that this API uses. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Object getObject(String elementName) throws Throwable { | |
Page page = PageManager.getPage(); // Get the current reference to the page I am on. | |
elementName = elementName.replaceAll("\\s+", "_").toLowerCase(); // Turn our text into all lower case with spaces replaced by underscores to match object names. | |
Method pageElementName = null; | |
try { | |
pageElementName = page.getClass().getMethod(elementName); // Create a Method object to store the PageElement we want to exercise. | |
} catch(NoSuchMethodException e) { | |
log.error("Element " + elementName + " is not defined for the page object " + page.getClass().toString() + ". Make sure you have spelled the page object name correctly in your Cucumber step definition and in the page object."); | |
throw e; | |
} |