├── .github └── workflows │ └── maven.yml ├── .gitignore ├── CONTRIBUTING.md ├── Jenkinsfile ├── LICENSE ├── README.md ├── pom.xml ├── public ├── index.html └── next_page.html └── src ├── main └── java │ └── com │ └── coveros │ └── selenified │ ├── Browser.java │ ├── Capabilities.java │ ├── Locator.java │ ├── Selenified.java │ ├── application │ ├── App.java │ ├── Assert.java │ ├── Check.java │ ├── Get.java │ ├── Is.java │ ├── Verify.java │ └── WaitFor.java │ ├── element │ ├── Element.java │ ├── Get.java │ ├── Is.java │ └── check │ │ ├── AssertContains.java │ │ ├── AssertEquals.java │ │ ├── AssertExcludes.java │ │ ├── AssertMatches.java │ │ ├── AssertState.java │ │ ├── Check.java │ │ ├── Contains.java │ │ ├── Equals.java │ │ ├── Excludes.java │ │ ├── Matches.java │ │ ├── State.java │ │ ├── VerifyContains.java │ │ ├── VerifyEquals.java │ │ ├── VerifyExcludes.java │ │ ├── VerifyMatches.java │ │ ├── VerifyState.java │ │ ├── WaitForEquals.java │ │ └── WaitForState.java │ ├── exceptions │ ├── InvalidBrowserException.java │ ├── InvalidBrowserOptionsException.java │ ├── InvalidBuildNameException.java │ ├── InvalidHTTPException.java │ ├── InvalidHubException.java │ ├── InvalidProxyException.java │ ├── InvalidReporterException.java │ └── InvalidSauceException.java │ ├── services │ ├── Call.java │ ├── HTTP.java │ ├── Request.java │ ├── Response.java │ └── check │ │ ├── AssertContains.java │ │ ├── AssertEquals.java │ │ ├── AssertExcludes.java │ │ ├── AssertMatches.java │ │ ├── Check.java │ │ ├── Contains.java │ │ ├── Equals.java │ │ ├── Excludes.java │ │ ├── Matches.java │ │ ├── VerifyContains.java │ │ ├── VerifyEquals.java │ │ ├── VerifyExcludes.java │ │ └── VerifyMatches.java │ └── utilities │ ├── Constants.java │ ├── Hub.java │ ├── LambdaTest.java │ ├── Listener.java │ ├── Property.java │ ├── ReportOverview.java │ ├── Reporter.java │ ├── Sauce.java │ ├── TestCase.java │ └── Transformer.java └── test ├── java ├── ConflictIT.java ├── TestCaseTest.java ├── integration │ ├── ActionDoIT.java │ ├── ActionGetIT.java │ ├── ActionGoIT.java │ ├── ActionIsIT.java │ ├── ActionSwitchIT.java │ ├── AssertContainsIT.java │ ├── AssertEqualsIT.java │ ├── AssertExcludesIT.java │ ├── AssertIT.java │ ├── AssertMatchesIT.java │ ├── AssertStateIT.java │ ├── ConflictIT.java │ ├── ElementIT.java │ ├── NoBrowserIT.java │ ├── NoJavascriptIT.java │ ├── NoLoadIT.java │ ├── OverrideIT.java │ ├── SelenifiedIT.java │ ├── ServicesBase.java │ ├── ServicesErrorIT.java │ ├── ServicesIT.java │ ├── ServicesOverrideIT.java │ ├── ServicesResponseAssertContainsIT.java │ ├── ServicesResponseAssertEqualsIT.java │ ├── ServicesResponseAssertExcludesIT.java │ ├── ServicesResponseAssertMatchesIT.java │ ├── ServicesResponseIT.java │ ├── ServicesResponseVerifyContainsIT.java │ ├── ServicesResponseVerifyEqualsIT.java │ ├── ServicesResponseVerifyExcludesIT.java │ ├── ServicesResponseVerifyMatchesIT.java │ ├── VerifyContainsIT.java │ ├── VerifyEqualsIT.java │ ├── VerifyExcludesIT.java │ ├── VerifyIT.java │ ├── VerifyMatchesIT.java │ ├── VerifyStateIT.java │ ├── WaitForEqualsIT.java │ ├── WaitForIT.java │ ├── WaitForStateIT.java │ ├── WebBase.java │ └── hub │ │ ├── LambdaTestIT.java │ │ └── SauceIT.java ├── sample │ ├── MainPage.java │ ├── POMSampleIT.java │ ├── ReadmeSampleIT.java │ └── SimpleSampleIT.java └── unit │ ├── AppTest.java │ ├── BrowserTest.java │ ├── CallTest.java │ ├── CapabilitiesTest.java │ ├── ElementTest.java │ ├── ExceptionTest.java │ ├── HTTPTest.java │ ├── HubTest.java │ ├── ListenerTest.java │ ├── PropertyTest.java │ ├── ReportOverviewTest.java │ ├── ReporterTest.java │ ├── RequestTest.java │ ├── ResponseTest.java │ ├── SauceTest.java │ ├── SaveProperties.java │ ├── ServicesAssertContainsTest.java │ ├── ServicesAssertEqualsTest.java │ ├── ServicesAssertExcludesTest.java │ ├── ServicesAssertMatchesTest.java │ ├── ServicesCheckTest.java │ ├── ServicesVerifyContainsTest.java │ ├── ServicesVerifyEqualsTest.java │ ├── ServicesVerifyExcludesTest.java │ ├── ServicesVerifyMatchesTest.java │ └── TestCaseTest.java └── resources └── selenified.properties /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: Set up JDK 1.8 13 | uses: actions/setup-java@v1 14 | with: 15 | java-version: 1.8 16 | - name: Build with Maven 17 | run: mvn -B package --file pom.xml 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | test-output/ 11 | target/ 12 | doc/ 13 | docs/ 14 | 15 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 16 | hs_err_pid* 17 | /bin/ 18 | 19 | # eclipse stuff 20 | .metadata 21 | bin/ 22 | tmp/ 23 | *.tmp 24 | *.bak 25 | *.swp 26 | *~.nib 27 | local.properties 28 | .settings/ 29 | .loadpath 30 | .recommenders 31 | 32 | # intelliJ stuff 33 | .idea/ 34 | src/main/main.iml 35 | src/test/test.iml 36 | selenified.iml 37 | 38 | # Eclipse Core 39 | .project 40 | 41 | # External tool builders 42 | .externalToolBuilders/ 43 | 44 | # Locally stored "Eclipse launch configurations" 45 | *.launch 46 | 47 | # PyDev specific (Python IDE for Eclipse) 48 | *.pydevproject 49 | 50 | # CDT-specific (C/C++ Development Tooling) 51 | .cproject 52 | 53 | # JDT-specific (Eclipse Java Development Tools) 54 | .classpath 55 | 56 | # Java annotation processor (APT) 57 | .factorypath 58 | 59 | # PDT-specific (PHP Development Tools) 60 | .buildpath 61 | 62 | # sbteclipse plugin 63 | .target 64 | 65 | # Tern plugin 66 | .tern-project 67 | 68 | # TeXlipse plugin 69 | .texlipse 70 | 71 | # STS (Spring Tool Suite) 72 | .springBeans 73 | 74 | # Code Recommenders 75 | .recommenders/ 76 | 77 | # Scala IDE specific (Scala & Java development for Eclipse) 78 | .cache-main 79 | .scala_dependencies 80 | .worksheet 81 | 82 | # Gradle 83 | .gradle 84 | /build/ 85 | 86 | # Ignore Gradle GUI config 87 | gradle-app.setting 88 | 89 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 90 | !gradle-wrapper.jar 91 | 92 | # Cache of project 93 | .gradletasknamecache 94 | 95 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 96 | # gradle/wrapper/gradle-wrapper.properties 97 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, 4 | email, or any other method with the owners of this repository before making a change. 5 | 6 | Please note we have a code of conduct, please follow it in all your interactions with the project. 7 | 8 | ## Pull Request Process 9 | 10 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a 11 | build. 12 | 2. Update the README.md with details of changes to the interface, this includes new environment 13 | variables, exposed ports, useful file locations and container parameters. 14 | 3. Ensure javadocs are provided for all public methods, as these are publicly hosted and used at 15 | [github.io](https://coveros.github.io/selenified) 16 | 4. Increase the version numbers in any examples files and the README.md to the new version that this 17 | Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 18 | 5. You may merge the Pull Request in once you have the sign-off of any other developers, and SonarQube 19 | and Jenkins build returns cleanly. If you do not have permission to do that, you may request the 20 | reviewer to merge it for you. 21 | 22 | More information can be found on the [workflow wiki page](https://github.com/Coveros/selenified/wiki/Development-Workflow) 23 | 24 | ## Code of Conduct 25 | 26 | ### Our Pledge 27 | 28 | In the interest of fostering an open and welcoming environment, we as 29 | contributors and maintainers pledge to making participation in our project and 30 | our community a harassment-free experience for everyone, regardless of age, body 31 | size, disability, ethnicity, gender identity and expression, level of experience, 32 | nationality, personal appearance, race, religion, or sexual identity and 33 | orientation. 34 | 35 | ### Our Standards 36 | 37 | Examples of behavior that contributes to creating a positive environment 38 | include: 39 | 40 | * Using welcoming and inclusive language 41 | * Being respectful of differing viewpoints and experiences 42 | * Gracefully accepting constructive criticism 43 | * Focusing on what is best for the community 44 | * Showing empathy towards other community members 45 | 46 | Examples of unacceptable behavior by participants include: 47 | 48 | * The use of sexualized language or imagery and unwelcome sexual attention or 49 | advances 50 | * Trolling, insulting/derogatory comments, and personal or political attacks 51 | * Public or private harassment 52 | * Publishing others' private information, such as a physical or electronic 53 | address, without explicit permission 54 | * Other conduct which could reasonably be considered inappropriate in a 55 | professional setting 56 | 57 | ### Our Responsibilities 58 | 59 | Project maintainers are responsible for clarifying the standards of acceptable 60 | behavior and are expected to take appropriate and fair corrective action in 61 | response to any instances of unacceptable behavior. 62 | 63 | Project maintainers have the right and responsibility to remove, edit, or 64 | reject comments, commits, code, wiki edits, issues, and other contributions 65 | that are not aligned to this Code of Conduct, or to ban temporarily or 66 | permanently any contributor for other behaviors that they deem inappropriate, 67 | threatening, offensive, or harmful. 68 | 69 | ### Scope 70 | 71 | This Code of Conduct applies both within project spaces and in public spaces 72 | when an individual is representing the project or its community. Examples of 73 | representing a project or community include using an official project e-mail 74 | address, posting via an official social media account, or acting as an appointed 75 | representative at an online or offline event. Representation of a project may be 76 | further defined and clarified by project maintainers. 77 | 78 | ### Enforcement 79 | 80 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 81 | reported by contacting the project team at [selenified@coveros.com](mailto:selenified@coveros.com). All 82 | complaints will be reviewed and investigated and will result in a response that 83 | is deemed necessary and appropriate to the circumstances. The project team is 84 | obligated to maintain confidentiality with regard to the reporter of an incident. 85 | Further details of specific enforcement policies may be posted separately. 86 | 87 | Project maintainers who do not follow or enforce the Code of Conduct in good 88 | faith may face temporary or permanent repercussions as determined by other 89 | members of the project's leadership. 90 | 91 | ### Attribution 92 | 93 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 94 | available at [http://contributor-covenant.org/version/1/4][version] 95 | 96 | [homepage]: http://contributor-covenant.org 97 | [version]: http://contributor-covenant.org/version/1/4/ -------------------------------------------------------------------------------- /public/next_page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
You're on the next page
5 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/Locator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified; 22 | 23 | /** 24 | * Select a Locator for the element we are interacting with Available options 25 | * are: xpath, id, name, classname, css, paritallinktext, linktext, tagname 26 | * 27 | * @author Max Saperstone 28 | * @version 3.3.1 29 | * @lastupdate 5/16/2018 30 | */ 31 | public enum Locator { 32 | XPATH, ID, NAME, CLASSNAME, CSS, PARTIALLINKTEXT, LINKTEXT, TAGNAME 33 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/application/Is.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.application; 22 | 23 | import org.openqa.selenium.By; 24 | import org.openqa.selenium.NoAlertPresentException; 25 | import org.openqa.selenium.WebDriver; 26 | import org.testng.log4testng.Logger; 27 | 28 | /** 29 | * Is checks information about the app in general, not specific to any 30 | * particular page or element. A boolean is always returning, indicating if an 31 | * object is present or not 32 | * 33 | * @author Max Saperstone 34 | * @version 3.3.1 35 | * @lastupdate 3/3/2019 36 | */ 37 | public class Is { 38 | 39 | private static final Logger log = Logger.getLogger(Is.class); 40 | 41 | // what locator actions are available in webdriver 42 | // this is the driver that will be used for all selenium actions 43 | private final WebDriver driver; 44 | 45 | public Is(WebDriver driver) { 46 | this.driver = driver; 47 | } 48 | 49 | // //////////////////////////////////// 50 | // checking element availability 51 | // //////////////////////////////////// 52 | 53 | /** 54 | * Determines if any popup is present on the page 55 | * 56 | * @return Boolean: is a popup present on the page 57 | */ 58 | private boolean isPopupPresent() { 59 | boolean isPresent = false; 60 | try { 61 | driver.switchTo().alert(); 62 | isPresent = true; 63 | } catch (NoAlertPresentException e) { 64 | log.info(e); 65 | } 66 | return isPresent; 67 | } 68 | 69 | /** 70 | * Determines if an alert is present on the page. 71 | * 72 | * @return Boolean: is an alert present 73 | */ 74 | public boolean alertPresent() { 75 | return isPopupPresent(); 76 | } 77 | 78 | /** 79 | * Determines if a confirmation is present on the page. 80 | * 81 | * @return Boolean: is a confirmation present 82 | */ 83 | public boolean confirmationPresent() { 84 | return isPopupPresent(); 85 | } 86 | 87 | /** 88 | * Determines if a prompt is present on the page. This information will not 89 | * be logged or recorded. 90 | * 91 | * @return Boolean: is a prompt present 92 | */ 93 | public boolean promptPresent() { 94 | return isPopupPresent(); 95 | } 96 | 97 | /** 98 | * Determines if the URL loaded is one expected. This information will not 99 | * be logged or recorded 100 | * 101 | * @return Boolean: is the url the expected one 102 | */ 103 | public boolean url(String location) { 104 | return location.equals(driver.getCurrentUrl()); 105 | } 106 | 107 | /** 108 | * Determines if a cookie exists in the application with the provided 109 | * cookieName. 110 | * 111 | * @param expectedCookieName - the name of the cookie 112 | * @return Boolean: if the cookie is present 113 | */ 114 | public boolean cookiePresent(String expectedCookieName) { 115 | boolean isCookiePresent = false; 116 | try { 117 | if (driver.manage().getCookieNamed(expectedCookieName) != null) { 118 | isCookiePresent = true; 119 | } 120 | return isCookiePresent; 121 | } catch (Exception e) { 122 | log.error(e); 123 | return false; 124 | } 125 | } 126 | 127 | /** 128 | * Determines if the provided text(s) are on the current page. 129 | * 130 | * @param expectedText - the text we are expecting to be present on the page 131 | * @return Boolean: whether or not the text is present 132 | */ 133 | public boolean textPresent(String expectedText) { 134 | try { 135 | String bodyText = driver.findElement(By.tagName("body")).getText(); 136 | return bodyText.contains(expectedText); 137 | } catch (Exception e) { 138 | log.info(e); 139 | return false; 140 | } 141 | } 142 | 143 | /** 144 | * Determines if the provides text is present in the current page source. 145 | * 146 | * @param expectedText - the text we are expecting to be present on the page 147 | * @return Boolean: whether or not the text is present 148 | */ 149 | public boolean textPresentInSource(String expectedText) { 150 | try { 151 | return driver.getPageSource().contains(expectedText); 152 | } catch (Exception e) { 153 | log.info(e); 154 | return false; 155 | } 156 | } 157 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/element/Is.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.element; 22 | 23 | import org.openqa.selenium.NoSuchElementException; 24 | import org.openqa.selenium.StaleElementReferenceException; 25 | import org.openqa.selenium.WebElement; 26 | import org.openqa.selenium.support.ui.Select; 27 | import org.testng.log4testng.Logger; 28 | 29 | /** 30 | * Is retrieves information about a particular element. A boolean is always 31 | * returning, indicating if an object is present or not 32 | * 33 | * @author Max Saperstone 34 | * @version 3.3.1 35 | * @lastupdate 3/7/2019 36 | */ 37 | public class Is { 38 | 39 | private static final Logger log = Logger.getLogger(Is.class); 40 | // constants 41 | private static final String SELECT = "select"; 42 | // what element are we trying to interact with on the page 43 | private final Element element; 44 | 45 | public Is(Element element) { 46 | this.element = element; 47 | } 48 | 49 | // //////////////////////////////////// 50 | // checking element availability 51 | // //////////////////////////////////// 52 | 53 | /** 54 | * Determines whether the element is present or not. 55 | * 56 | * @return Boolean: whether the element is present or not 57 | */ 58 | public boolean present() { 59 | boolean isPresent = false; 60 | try { 61 | element.getWebElement().getText(); 62 | isPresent = true; 63 | } catch (NoSuchElementException | StaleElementReferenceException e) { 64 | log.info(e); 65 | } 66 | return isPresent; 67 | } 68 | 69 | /** 70 | * Determines whether the element is an input or not. An input could be an 71 | * input element, a textarea, or a select 72 | * 73 | * @return Boolean: whether the element is an input or not 74 | */ 75 | public boolean input() { 76 | boolean isInput = false; 77 | try { 78 | String elementTag = element.get().tagName(); 79 | if ("input".equalsIgnoreCase(elementTag) || 80 | "textarea".equalsIgnoreCase(elementTag) || 81 | SELECT.equalsIgnoreCase(elementTag)) { 82 | isInput = true; 83 | } 84 | } catch (NoSuchElementException e) { 85 | log.info(e); 86 | } 87 | return isInput; 88 | } 89 | 90 | /** 91 | * Determines whether the element is a select or not. 92 | * 93 | * @return Boolean: whether the element is an input or not 94 | */ 95 | public boolean select() { 96 | boolean isSelect = false; 97 | try { 98 | if (SELECT.equalsIgnoreCase(element.get().tagName())) { 99 | isSelect = true; 100 | } 101 | } catch (NoSuchElementException e) { 102 | log.info(e); 103 | } 104 | return isSelect; 105 | } 106 | 107 | /** 108 | * Determines whether the element is a table or not. 109 | * 110 | * @return Boolean: whether the element is an input or not 111 | */ 112 | public boolean table() { 113 | boolean isTable = false; 114 | try { 115 | if ("table".equalsIgnoreCase(element.get().tagName())) { 116 | isTable = true; 117 | } 118 | } catch (NoSuchElementException e) { 119 | log.info(e); 120 | } 121 | return isTable; 122 | } 123 | 124 | /** 125 | * Determines whether the element is enabled or not. 126 | * 127 | * @return Boolean: whether the element is enabled or not 128 | */ 129 | public boolean enabled() { 130 | boolean isEnabled = false; 131 | try { 132 | // adding additional check for disabled attribute, due to issues with safari 133 | isEnabled = (element.getWebElement().isEnabled() && !element.get().allAttributes().containsKey("disabled")); 134 | } catch (NullPointerException | NoSuchElementException e) { 135 | // Null pointer means the element was deleted, and there has no attributes. No such element means the same thing 136 | log.info(e); 137 | } 138 | return isEnabled; 139 | } 140 | 141 | /** 142 | * Determines whether the element is editable or not. To be editable, it must 143 | * be an input, and enabled 144 | * 145 | * @return Boolean: whether the element is editable or not 146 | */ 147 | public boolean editable() { 148 | return enabled() && input(); 149 | } 150 | 151 | /** 152 | * Determines whether the element is checked or not. 153 | * 154 | * @return Boolean: whether the element is checked or not 155 | */ 156 | public boolean checked() { 157 | boolean isChecked = false; 158 | try { 159 | isChecked = element.getWebElement().isSelected(); 160 | } catch (Exception e) { 161 | log.info(e); 162 | } 163 | return isChecked; 164 | } 165 | 166 | /** 167 | * Determines whether the element is displayed or not. 168 | * 169 | * @return Boolean: whether the element is displayed or not 170 | */ 171 | public boolean displayed() { 172 | boolean isDisplayed = false; 173 | try { 174 | isDisplayed = element.getWebElement().isDisplayed(); 175 | } catch (NoSuchElementException e) { 176 | log.info(e); 177 | } 178 | return isDisplayed; 179 | } 180 | 181 | /** 182 | * Determines whether the element has something selected or not. Checkboxes, 183 | * radio buttons, and selects could all have something selected. Other 184 | * elements will default to false. 185 | * 186 | * @return Boolean: is something selected or not 187 | */ 188 | public boolean somethingSelected() { 189 | boolean isSelected = false; 190 | if (input()) { 191 | String elementTag = element.get().tagName(); 192 | WebElement webElement = element.getWebElement(); 193 | if ("input".equalsIgnoreCase(elementTag)) { 194 | isSelected = webElement.isSelected(); 195 | } else if (SELECT.equalsIgnoreCase(elementTag)) { 196 | Select dropdown = new Select(webElement); 197 | isSelected = !dropdown.getAllSelectedOptions().isEmpty(); 198 | } 199 | } 200 | return isSelected; 201 | } 202 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/element/check/VerifyExcludes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.element.check; 22 | 23 | import com.coveros.selenified.element.Element; 24 | import com.coveros.selenified.utilities.Reporter; 25 | 26 | /** 27 | * VerifyExcludes implements Excludes to provide some additional verification 28 | * capabilities. It will handle all verifications performed on the actual 29 | * element. These asserts are custom to the framework, and in addition to 30 | * providing easy object oriented capabilities, they take screenshots with each 31 | * verification to provide additional traceability, and assist in 32 | * troubleshooting and debugging failing tests. Excludes checks that elements 33 | * don't have a particular value associated to them. 34 | * 35 | * @author Max Saperstone 36 | * @version 3.3.1 37 | * @lastupdate 8/08/2019 38 | */ 39 | public class VerifyExcludes extends Excludes { 40 | 41 | /** 42 | * The default constructor passing in the element and output file 43 | * 44 | * @param element - the element under test 45 | * @param reporter - the file to write all logging out to 46 | */ 47 | public VerifyExcludes(Element element, Reporter reporter) { 48 | this.element = element; 49 | this.reporter = reporter; 50 | } 51 | 52 | // /////////////////////////////////////// 53 | // assessing functionality 54 | // /////////////////////////////////////// 55 | 56 | /** 57 | * Verifies that the element's class does not contain the provided expected 58 | * class. If the element isn't present, this will constitute a failure, same 59 | * as a mismatch. This information will be logged and recorded, with a 60 | * screenshot for traceability and added debugging support. 61 | * 62 | * @param unexpectedClass - the unexpected class value 63 | */ 64 | public void clazz(String unexpectedClass) { 65 | checkClazz(unexpectedClass, 0, 0); 66 | } 67 | 68 | /** 69 | * Verifies that the element does not contain the provided expected 70 | * attribute. If the element isn't present, this will constitute a failure, 71 | * same as a mismatch. This information will be logged and recorded, with a 72 | * screenshot for traceability and added debugging support. 73 | * 74 | * @param expectedAttribute - the attribute to check for 75 | */ 76 | public void attribute(String expectedAttribute) { 77 | checkAttribute(expectedAttribute, 0, 0); 78 | } 79 | 80 | /** 81 | * Verifies that the element's text does not contain the provided expected 82 | * text. If the element isn't present, this will constitute a failure, same 83 | * as a mismatch. This information will be logged and recorded, with a 84 | * screenshot for traceability and added debugging support. 85 | * 86 | * @param expectedText the expected text of the element 87 | */ 88 | public void text(String expectedText) { 89 | checkText(expectedText, 0, 0); 90 | } 91 | 92 | /** 93 | * Verifies that the element's text does not contain the provided expected 94 | * text. If the element isn't present, this will constitute a failure, same 95 | * as a mismatch. This information will be logged and recorded, with a 96 | * screenshot for traceability and added debugging support. 97 | * 98 | * @param row - the number of the row in the table - note, row numbering 99 | * starts at 0 100 | * @param col - the number of the column in the table - note, column 101 | * numbering starts at 0 102 | * @param expectedText the expected text of the element 103 | */ 104 | public void text(int row, int col, String expectedText) { 105 | checkText(row, col, expectedText, 0, 0); 106 | } 107 | 108 | /** 109 | * Verifies that the element's value does not contain the provided expected 110 | * value. If the element isn't present or an input, this will constitute a 111 | * failure, same as a mismatch. This information will be logged and 112 | * recorded, with a screenshot for traceability and added debugging support. 113 | * 114 | * @param expectedValue the expected value of the element 115 | */ 116 | public void value(String expectedValue) { 117 | checkValue(expectedValue, 0, 0); 118 | } 119 | 120 | /** 121 | * Verifies that the element's options do not contain the provided expected 122 | * option. If the element isn't present or a select, this will constitute a 123 | * failure, same as a mismatch. This information will be logged and 124 | * recorded, with a screenshot for traceability and added debugging support. 125 | * 126 | * @param expectedOption the option not expected in the list 127 | */ 128 | public void selectOption(String expectedOption) { 129 | checkSelectOption(expectedOption, 0, 0); 130 | } 131 | 132 | /** 133 | * Verifies that the element's options do not contain the provided expected 134 | * value. If the element isn't present or a select, this will constitute a 135 | * failure, same as a mismatch. This information will be logged and 136 | * recorded, with a screenshot for traceability and added debugging support. 137 | * 138 | * @param expectedValue the unexpected input value of the element 139 | */ 140 | public void selectValue(String expectedValue) { 141 | checkSelectValue(expectedValue, 0, 0); 142 | } 143 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/element/check/VerifyMatches.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.element.check; 22 | 23 | import com.coveros.selenified.element.Element; 24 | import com.coveros.selenified.utilities.Reporter; 25 | 26 | /** 27 | * VerifyMatches extends Matches to provide some additional verification capabilities. 28 | * It will handle all verifications performed on the actual element. These 29 | * asserts are custom to the framework, and in addition to providing easy object 30 | * oriented capabilities, they take screenshots with each verification to 31 | * provide additional traceability, and assist in troubleshooting and debugging 32 | * failing tests. Matches checks that elements have a particular value associated 33 | * to them that fits the provided regular expression. 34 | * 35 | * @author Max Saperstone 36 | * @version 3.3.1 37 | * @lastupdate 8/08/2019 38 | */ 39 | public class VerifyMatches extends Matches { 40 | 41 | /** 42 | * The default constructor passing in the element and output file 43 | * 44 | * @param element - the element under test 45 | * @param reporter - the file to write all logging out to 46 | */ 47 | public VerifyMatches(Element element, Reporter reporter) { 48 | this.element = element; 49 | this.reporter = reporter; 50 | } 51 | 52 | // /////////////////////////////////////// 53 | // assessing functionality 54 | // /////////////////////////////////////// 55 | 56 | /** 57 | * Verifies that the element's text matches the regular expression pattern provided. If 58 | * the element isn't present, this will constitute a failure, same as a 59 | * mismatch. This information will be logged and recorded, with a screenshot 60 | * for traceability and added debugging support. 61 | * 62 | * @param expectedPattern the expected pattern of the text of the element 63 | */ 64 | public void text(String expectedPattern) { 65 | checkText(expectedPattern, 0, 0); 66 | } 67 | 68 | /** 69 | * Verifies that the element's pattern in a particular cell matches the regular expression 70 | * pattern provided. If the element isn't present, or a table, this will 71 | * constitute a failure, same as a mismatch. This information will be logged 72 | * and recorded, with a screenshot for traceability and added debugging 73 | * support. 74 | * 75 | * @param row - the number of the row in the table - note, row numbering 76 | * starts at 1, NOT 0 77 | * @param col - the number of the column in the table - note, column 78 | * numbering starts at 1, NOT 0 79 | * @param pattern - what pattern do we expect to be in the table cell 80 | */ 81 | public void text(int row, int col, String pattern) { 82 | checkText(row, col, pattern, 0, 0); 83 | } 84 | 85 | /** 86 | * Verifies that the element's value matches the regular expression pattern 87 | * provided. If the element isn't present or an input, this will constitute a failure, 88 | * same as a mismatch. This information will be logged and recorded, with a 89 | * screenshot for traceability and added debugging support. 90 | * 91 | * @param expectedPattern the expected input value of the element 92 | */ 93 | public void value(String expectedPattern) { 94 | checkValue(expectedPattern, 0, 0); 95 | } 96 | 97 | /** 98 | * Verifies that the element's selected option matches the regular expression pattern 99 | * provided. If the element isn't present or a select, this will constitute a 100 | * failure, same as a mismatch. This information will be logged and 101 | * recorded, with a screenshot for traceability and added debugging support. 102 | * 103 | * @param expectedPattern the expected input text of the element 104 | */ 105 | public void selectedOption(String expectedPattern) { 106 | checkSelectedOption(expectedPattern, 0, 0); 107 | } 108 | 109 | /** 110 | * Verifies that the element's selected value matches the regular expression pattern 111 | * provided. If the element isn't present or a select, this will constitute a 112 | * failure, same as a mismatch. This information will be logged and 113 | * recorded, with a screenshot for traceability and added debugging support. 114 | * 115 | * @param expectedPattern the expected input value of the element 116 | */ 117 | public void selectedValue(String expectedPattern) { 118 | checkSelectedValue(expectedPattern, 0, 0); 119 | } 120 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/element/check/VerifyState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.element.check; 22 | 23 | import com.coveros.selenified.element.Element; 24 | import com.coveros.selenified.utilities.Reporter; 25 | 26 | /** 27 | * VerifyState implements State to provide some additional verification capabilities. 28 | * It will handle all verifications performed on the actual element. These 29 | * asserts are custom to the framework, and in addition to providing easy object 30 | * oriented capabilities, they take screenshots with each verification to 31 | * provide additional traceability, and assist in troubleshooting and debugging 32 | * failing tests. State checks that elements are in a particular state. 33 | * 34 | * @author Max Saperstone 35 | * @version 3.3.1 36 | * @lastupdate 8/08/2019 37 | */ 38 | public class VerifyState extends State { 39 | 40 | /** 41 | * The default constructor passing in the element and output file 42 | * 43 | * @param element - the element under test 44 | * @param reporter - the file to write all logging out to 45 | */ 46 | public VerifyState(Element element, Reporter reporter) { 47 | this.element = element; 48 | this.reporter = reporter; 49 | } 50 | 51 | // /////////////////////////////////////// 52 | // assessing functionality 53 | // /////////////////////////////////////// 54 | 55 | /** 56 | * Verifies that the element is present. This information will be logged and 57 | * recorded, with a screenshot for traceability and added debugging support. 58 | */ 59 | public void present() { 60 | checkPresent(0, 0); 61 | } 62 | 63 | /** 64 | * Verifies that the element is not present. This information will be 65 | * logged and recorded, with a screenshot for traceability and added 66 | * debugging support. 67 | */ 68 | public void notPresent() { 69 | checkNotPresent(0, 0); 70 | } 71 | 72 | /** 73 | * Verifies that the element is displayed. This information will be logged and 74 | * recorded, with a screenshot for traceability and added debugging support. 75 | */ 76 | public void displayed() { 77 | checkDisplayed(0, 0); 78 | } 79 | 80 | /** 81 | * Verifies that the element is not displayed. This information will be logged 82 | * and recorded, with a screenshot for traceability and added debugging 83 | * support. 84 | */ 85 | public void notDisplayed() { 86 | checkNotDisplayed(0, 0); 87 | } 88 | 89 | /** 90 | * Verifies that the element is checked. This information will be logged and 91 | * recorded, with a screenshot for traceability and added debugging support. 92 | */ 93 | public void checked() { 94 | checkChecked(0, 0); 95 | } 96 | 97 | /** 98 | * Verifies that the element is not checked. This information will be logged 99 | * and recorded, with a screenshot for traceability and added debugging 100 | * support. 101 | */ 102 | public void notChecked() { 103 | checkNotChecked(0, 0); 104 | } 105 | 106 | /** 107 | * Verifies that the element is editable. If the element isn't an input, this will 108 | * constitute a failure, same as it not being editable. This information 109 | * will be logged and recorded, with a screenshot for traceability and added 110 | * debugging support. 111 | */ 112 | public void editable() { 113 | checkEditable(0, 0); 114 | } 115 | 116 | /** 117 | * Verifies that the element is not editable. If the element isn't an input, 118 | * this will constitute a pass, as non input elements are not editable. This 119 | * information will be logged and recorded, with a screenshot for 120 | * traceability and added debugging support. 121 | */ 122 | public void notEditable() { 123 | checkNotEditable(0, 0); 124 | } 125 | 126 | /** 127 | * Verifies that the element is enabled. This information will be logged and recorded, with 128 | * a screenshot for traceability and added debugging support. 129 | */ 130 | public void enabled() { 131 | checkEnabled(0, 0); 132 | } 133 | 134 | /** 135 | * Verifies that the element is not enabled. This information will be logged and recorded, with 136 | * a screenshot for traceability and added debugging support. 137 | */ 138 | public void notEnabled() { 139 | checkNotEnabled(0, 0); 140 | } 141 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/exceptions/InvalidBrowserException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.exceptions; 22 | 23 | import java.io.IOException; 24 | 25 | public class InvalidBrowserException extends IOException { 26 | 27 | private static final long serialVersionUID = 1560310848170077852L; 28 | 29 | public InvalidBrowserException(String msg) { 30 | super(msg); 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/exceptions/InvalidBrowserOptionsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.exceptions; 22 | 23 | public class InvalidBrowserOptionsException extends InvalidBrowserException { 24 | 25 | public InvalidBrowserOptionsException(String msg) { 26 | super(msg); 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/exceptions/InvalidBuildNameException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.exceptions; 22 | 23 | public class InvalidBuildNameException extends InvalidBrowserException { 24 | 25 | public InvalidBuildNameException(String msg) { 26 | super(msg); 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/exceptions/InvalidHTTPException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.exceptions; 22 | 23 | import java.io.IOException; 24 | 25 | public class InvalidHTTPException extends IOException { 26 | 27 | public InvalidHTTPException(String msg) { 28 | super(msg); 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/exceptions/InvalidHubException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.exceptions; 22 | 23 | import java.net.MalformedURLException; 24 | 25 | public class InvalidHubException extends MalformedURLException { 26 | 27 | public InvalidHubException(String msg) { 28 | super(msg); 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/exceptions/InvalidProxyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.exceptions; 22 | 23 | public class InvalidProxyException extends InvalidHTTPException { 24 | 25 | public InvalidProxyException(String msg) { 26 | super(msg); 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/exceptions/InvalidReporterException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.exceptions; 22 | 23 | import java.io.IOException; 24 | 25 | public class InvalidReporterException extends IOException { 26 | 27 | public InvalidReporterException(String msg) { 28 | super(msg); 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/exceptions/InvalidSauceException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.exceptions; 22 | 23 | public class InvalidSauceException extends InvalidHubException { 24 | 25 | public InvalidSauceException(String msg) { 26 | super(msg); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/services/Request.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.services; 22 | 23 | import com.google.gson.JsonElement; 24 | 25 | import java.util.Map; 26 | 27 | /** 28 | * A class designed to hold data needed to provide to the HTTP calls. 29 | * 30 | * @author Max Saperstone 31 | * @version 3.3.1 32 | * @lastupdate 8/30/2018 33 | */ 34 | public class Request { 35 | private Map urlParams = null; 36 | private JsonElement jsonPayload = null; 37 | private Map multipartData = null; 38 | 39 | public JsonElement getJsonPayload() { 40 | return jsonPayload; 41 | } 42 | 43 | public Request setJsonPayload(JsonElement jsonPayload) { 44 | this.jsonPayload = jsonPayload; 45 | return this; 46 | } 47 | 48 | public Map getUrlParams() { 49 | return urlParams; 50 | } 51 | 52 | public Request setUrlParams(Map urlParams) { 53 | this.urlParams = urlParams; 54 | return this; 55 | } 56 | 57 | public Map getMultipartData() { 58 | return multipartData; 59 | } 60 | 61 | public Request setMultipartData(Map multipartData) { 62 | this.multipartData = multipartData; 63 | return this; 64 | } 65 | 66 | /** 67 | * Determines if either the jsonPayload or multipart data is set 68 | * 69 | * @return Boolean: true if either jsonpayload or multipartdata is set 70 | */ 71 | public boolean isPayload() { 72 | return (jsonPayload != null || multipartData != null); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/services/Response.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.services; 22 | 23 | import com.coveros.selenified.services.check.*; 24 | import com.coveros.selenified.utilities.Reporter; 25 | import com.google.gson.JsonArray; 26 | import com.google.gson.JsonObject; 27 | 28 | import java.util.Map; 29 | 30 | /** 31 | * A class designed to hold data provided from the HTTP calls. 32 | * 33 | * @author Max Saperstone 34 | * @version 3.3.1 35 | * @lastupdate 1/6/2020 36 | */ 37 | public class Response { 38 | 39 | private final Map headers; 40 | private final int code; 41 | private final JsonObject object; 42 | private final JsonArray array; 43 | private final String message; 44 | 45 | // the assert class to check information about the response 46 | private final AssertContains assertContains; 47 | private final AssertEquals assertEquals; 48 | private final AssertExcludes assertExcludes; 49 | private final AssertMatches assertMatches; 50 | 51 | // the verify class to check information about the response 52 | private final VerifyContains verifyContains; 53 | private final VerifyEquals verifyEquals; 54 | private final VerifyExcludes verifyExcludes; 55 | private final VerifyMatches verifyMatches; 56 | 57 | public Response(Reporter reporter, Map headers, int code, JsonObject object, JsonArray array, String message) { 58 | this.headers = headers; 59 | this.code = code; 60 | this.object = object; 61 | this.array = array; 62 | this.message = message; 63 | this.assertContains = new AssertContains(this, reporter); 64 | this.assertEquals = new AssertEquals(this, reporter); 65 | this.assertExcludes = new AssertExcludes(this, reporter); 66 | this.assertMatches = new AssertMatches(this, reporter); 67 | this.verifyContains = new VerifyContains(this, reporter); 68 | this.verifyEquals = new VerifyEquals(this, reporter); 69 | this.verifyExcludes = new VerifyExcludes(this, reporter); 70 | this.verifyMatches = new VerifyMatches(this, reporter); 71 | } 72 | 73 | /** 74 | * Asserts that the services response will contain expected data. 75 | * These asserts are custom to the framework, and in addition to providing 76 | * easy object oriented they provide additional traceability, and assist in 77 | * troubleshooting and debugging failing tests. A failed assert will cause 78 | * the test to immediately stop on the error. 79 | */ 80 | public AssertContains assertContains() { 81 | return assertContains; 82 | } 83 | 84 | /** 85 | * Asserts that the services response will equals expected data. 86 | * These asserts are custom to the framework, and in addition to providing 87 | * easy object oriented they provide additional traceability, and assist in 88 | * troubleshooting and debugging failing tests. A failed assert will cause 89 | * the test to immediately stop on the error. 90 | */ 91 | public AssertEquals assertEquals() { 92 | return assertEquals; 93 | } 94 | 95 | /** 96 | * Asserts that the services response will not contain expected data. 97 | * These asserts are custom to the framework, and in addition to providing 98 | * easy object oriented they provide additional traceability, and assist in 99 | * troubleshooting and debugging failing tests. A failed assert will cause 100 | * the test to immediately stop on the error. 101 | */ 102 | public AssertExcludes assertExcludes() { 103 | return assertExcludes; 104 | } 105 | 106 | /** 107 | * Asserts that the services response will match the expected data. 108 | * These asserts are custom to the framework, and in addition to providing 109 | * easy object oriented they provide additional traceability, and assist in 110 | * troubleshooting and debugging failing tests. A failed assert will cause 111 | * the test to immediately stop on the error. 112 | */ 113 | public AssertMatches assertMatches() { 114 | return assertMatches; 115 | } 116 | 117 | /** 118 | * Verifies that the services response will contain expected data. 119 | * These asserts are custom to the framework, and in addition to providing 120 | * easy object oriented they provide additional traceability, and assist in 121 | * troubleshooting and debugging failing tests. 122 | */ 123 | public VerifyContains verifyContains() { 124 | return verifyContains; 125 | } 126 | 127 | /** 128 | * Verifies that the services response will equals expected data. 129 | * These asserts are custom to the framework, and in addition to providing 130 | * easy object oriented they provide additional traceability, and assist in 131 | * troubleshooting and debugging failing tests. 132 | */ 133 | public VerifyEquals verifyEquals() { 134 | return verifyEquals; 135 | } 136 | 137 | /** 138 | * Verifies that the services response will not contain expected data. 139 | * These asserts are custom to the framework, and in addition to providing 140 | * easy object oriented they provide additional traceability, and assist in 141 | * troubleshooting and debugging failing tests. 142 | */ 143 | public VerifyExcludes verifyExcludes() { 144 | return verifyExcludes; 145 | } 146 | 147 | /** 148 | * Verifies that the services response will match the expected data. 149 | * These asserts are custom to the framework, and in addition to providing 150 | * easy object oriented they provide additional traceability, and assist in 151 | * troubleshooting and debugging failing tests. 152 | */ 153 | public VerifyMatches verifyMatches() { 154 | return verifyMatches; 155 | } 156 | 157 | public Map getHeaders() { 158 | return headers; 159 | } 160 | 161 | public int getCode() { 162 | return code; 163 | } 164 | 165 | public boolean isData() { 166 | return object != null || array != null; 167 | } 168 | 169 | public JsonArray getArrayData() { 170 | return array; 171 | } 172 | 173 | public JsonObject getObjectData() { 174 | return object; 175 | } 176 | 177 | public String getMessage() { 178 | return message; 179 | } 180 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/services/check/AssertContains.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.services.check; 22 | 23 | import com.coveros.selenified.services.Response; 24 | import com.coveros.selenified.utilities.Reporter; 25 | import com.google.gson.JsonElement; 26 | 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | import static com.coveros.selenified.utilities.Constants.EXPECTED_TO_FIND; 31 | import static com.coveros.selenified.utilities.Constants.GSON; 32 | import static org.testng.AssertJUnit.assertTrue; 33 | 34 | /** 35 | * Assert will handle all verifications performed on the actual web services 36 | * calls themselves. These asserts are custom to the framework, and in addition to 37 | * providing easy object oriented capabilities, they assist in 38 | * troubleshooting and debugging failing tests. 39 | * 40 | * @author Max Saperstone 41 | * @version 3.3.1 42 | * @lastupdate 10/24/2019 43 | */ 44 | public class AssertContains extends Contains { 45 | 46 | /** 47 | * The default constructor passing in the app and output file 48 | * 49 | * @param response - the response from the web services call 50 | * @param reporter - the file to write all logging out to 51 | */ 52 | public AssertContains(Response response, Reporter reporter) { 53 | this.response = response; 54 | this.reporter = reporter; 55 | } 56 | 57 | /////////////////////////////////////////////////////// 58 | // assertions about the page in general 59 | /////////////////////////////////////////////////////// 60 | 61 | /** 62 | * Asserts the actual response json payload contains each key provided, 63 | * and writes that to the output file. If this fails, the code will 64 | * immediately exit, and record the error. 65 | * 66 | * @param expectedKeys a list with string keys expected in the json 67 | * response 68 | */ 69 | @Override 70 | public void keys(List expectedKeys) { 71 | assertTrue(EXPECTED_TO_FIND + String.join(", ", expectedKeys), checkKeys(expectedKeys)); 72 | } 73 | 74 | /** 75 | * Asserts the actual response json payload contains each of the pair 76 | * values provided, and writes that to the output file. If this fails, the code will 77 | * immediately exit, and record the error. 78 | * 79 | * @param expectedPairs a hashmap with string key value pairs expected in the json 80 | * response 81 | */ 82 | @Override 83 | public void keyValues(Map expectedPairs) { 84 | assertTrue(EXPECTED_TO_FIND + Reporter.formatKeyPair(expectedPairs), checkKeyValues(expectedPairs)); 85 | } 86 | 87 | /** 88 | * Asserts the actual response json payload contains a key containing a JsonObject 89 | * containing each of the keys provided. The jsonKeys should be passed in 90 | * as crumbs of the keys leading to the field with 91 | * the expected value. This result will be written out to the output file. 92 | * If this fails, the code will immediately exit, and record the error. 93 | * 94 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 95 | * @param expectedKeys - a list with string keys expected in the json 96 | * response 97 | */ 98 | @Override 99 | public void nestedKeys(List jsonKeys, List expectedKeys) { 100 | assertTrue(EXPECTED_TO_FIND + String.join(", ", expectedKeys), checkNestedKeys(jsonKeys, expectedKeys)); 101 | } 102 | 103 | /** 104 | * Asserts the actual response json payload contains a key containing a JsonObject 105 | * containing each of the pair values provided. The jsonKeys should be passed in 106 | * as crumbs of the keys leading to the field with 107 | * the expected value. This result will be written out to the output file. If this fails, the code will 108 | * immediately exit, and record the error. 109 | * 110 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 111 | * @param expectedPairs a hashmap with string key value pairs expected in the json 112 | * response 113 | */ 114 | @Override 115 | public void nestedKeyValues(List jsonKeys, Map expectedPairs) { 116 | assertTrue(EXPECTED_TO_FIND + Reporter.formatKeyPair(expectedPairs), checkNestedKeyValues(jsonKeys, expectedPairs)); 117 | } 118 | 119 | /** 120 | * Asserts the actual response json payload contains a key containing a JsonElement. 121 | * The jsonKeys should be passed in as crumbs of the keys leading to the field with 122 | * the expected value. This result will be written out to the output file. If this fails, the code will 123 | * immediately exit, and record the error. 124 | * 125 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 126 | * @param expectedJson - the expected response json array 127 | */ 128 | @Override 129 | public void nestedValue(List jsonKeys, JsonElement expectedJson) { 130 | assertTrue(EXPECTED_TO_FIND + GSON.toJson(expectedJson), checkNestedValue(jsonKeys, expectedJson)); 131 | } 132 | 133 | /** 134 | * Asserts the actual response json payload contains to the expected json 135 | * element, and writes that out to the output file. If this fails, the code will 136 | * immediately exit, and record the error. 137 | * 138 | * @param expectedJson - the expected response json array 139 | */ 140 | @Override 141 | public void value(JsonElement expectedJson) { 142 | assertTrue(EXPECTED_TO_FIND + GSON.toJson(expectedJson), checkValue(expectedJson)); 143 | } 144 | 145 | /** 146 | * Asserts the actual response json payload contains to the expected json 147 | * element, and writes that out to the output file. If this fails, the code will 148 | * immediately exit, and record the error. 149 | * 150 | * @param expectedMessage - the expected response json array 151 | */ 152 | @Override 153 | public void message(String expectedMessage) { 154 | assertTrue("Expected to find '" + expectedMessage + "'", checkMessage(expectedMessage)); 155 | } 156 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/services/check/AssertEquals.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.services.check; 22 | 23 | import com.coveros.selenified.services.Response; 24 | import com.coveros.selenified.utilities.Reporter; 25 | import com.google.gson.JsonArray; 26 | import com.google.gson.JsonObject; 27 | 28 | import java.util.List; 29 | 30 | import static org.testng.AssertJUnit.assertEquals; 31 | 32 | /** 33 | * Assert will handle all verifications performed on the actual web services 34 | * calls themselves. These asserts are custom to the framework, and in addition to 35 | * providing easy object oriented capabilities, they assist in 36 | * troubleshooting and debugging failing tests. 37 | * 38 | * @author Max Saperstone 39 | * @version 3.3.1 40 | * @lastupdate 10/24/2019 41 | */ 42 | public class AssertEquals extends Equals { 43 | 44 | /** 45 | * The default constructor passing in the app and output file 46 | * 47 | * @param response - the response from the web services call 48 | * @param reporter - the file to write all logging out to 49 | */ 50 | public AssertEquals(Response response, Reporter reporter) { 51 | this.response = response; 52 | this.reporter = reporter; 53 | } 54 | 55 | /////////////////////////////////////////////////////// 56 | // assertions about the page in general 57 | /////////////////////////////////////////////////////// 58 | 59 | /** 60 | * Asserts the actual response code is equals to the expected response 61 | * code, and writes that out to the output file. If this fails, the code will 62 | * immediately exit, and record the error. 63 | * 64 | * @param expectedCode - the expected response code 65 | */ 66 | @Override 67 | public void code(int expectedCode) { 68 | assertEquals("Code Mismatch", expectedCode, checkCode(expectedCode)); 69 | } 70 | 71 | /** 72 | * Asserts the actual response json payload is equal to the expected 73 | * response json payload, and writes that out to the output file. If this fails, the code will 74 | * immediately exit, and record the error. 75 | * 76 | * @param expectedJson - the expected response json object 77 | */ 78 | @Override 79 | public void objectData(JsonObject expectedJson) { 80 | assertEquals("JsonObject Response Mismatch", expectedJson, checkObjectData(expectedJson)); 81 | } 82 | 83 | /** 84 | * Asserts the actual response json payload is equal to the expected 85 | * response json payload, and writes that out to the output file. If this fails, the code will 86 | * immediately exit, and record the error. 87 | * 88 | * @param expectedJson - the expected response json array 89 | */ 90 | @Override 91 | public void arrayData(JsonArray expectedJson) { 92 | assertEquals("JsonArray Response Mismatch", expectedJson, checkArrayData(expectedJson)); 93 | } 94 | 95 | /** 96 | * Asserts the actual response json payload contains a key with a value equal to the expected 97 | * value. The jsonKeys should be passed in as crumbs of the keys leading to the field with 98 | * the expected value. This result will be written out to the output file. If this fails, the code will 99 | * immediately exit, and record the error. 100 | * 101 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 102 | * @param expectedValue - the expected value 103 | */ 104 | @Override 105 | public void nestedValue(List jsonKeys, Object expectedValue) { 106 | assertEquals("JsonElement Response Mismatch", expectedValue, checkNestedValue(jsonKeys, expectedValue)); 107 | } 108 | 109 | /** 110 | * Asserts the actual response payload is equal to the expected 111 | * response payload, and writes that out to the output file. If this fails, the code will 112 | * immediately exit, and record the error. 113 | * 114 | * @param expectedMessage - the expected response message 115 | */ 116 | @Override 117 | public void message(String expectedMessage) { 118 | assertEquals("Response Message Mismatch", expectedMessage, checkMessage(expectedMessage)); 119 | } 120 | 121 | /** 122 | * Asserts the actual response payload contains the number of elements 123 | * in an array as expected, and writes that out to the output file. If this fails, the code will 124 | * immediately exit, and record the error. 125 | * 126 | * @param expectedSize - the expected array size 127 | */ 128 | @Override 129 | public void arraySize(int expectedSize) { 130 | assertEquals("Response Array Size Mismatch", expectedSize, checkArraySize(expectedSize)); 131 | } 132 | 133 | /** 134 | * Asserts the actual response payload contains a key with a value of the number of elements 135 | * in an array as expected, and writes that out to the output file. If this fails, the code will 136 | * immediately exit, and record the error. 137 | * 138 | * @param expectedSize - the expected array size 139 | */ 140 | @Override 141 | public void nestedArraySize(List jsonKeys, int expectedSize) { 142 | assertEquals("Response Array Size Mismatch", expectedSize, checkNestedArraySize(jsonKeys, expectedSize)); 143 | } 144 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/services/check/AssertExcludes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.services.check; 22 | 23 | import com.coveros.selenified.services.Response; 24 | import com.coveros.selenified.utilities.Reporter; 25 | import com.google.gson.JsonElement; 26 | 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | import static com.coveros.selenified.utilities.Constants.EXPECTED_NOT_TO_FIND; 31 | import static com.coveros.selenified.utilities.Constants.GSON; 32 | import static org.testng.AssertJUnit.assertTrue; 33 | 34 | /** 35 | * Assert will handle all verifications performed on the actual web services 36 | * calls themselves. These asserts are custom to the framework, and in addition to 37 | * providing easy object oriented capabilities, they assist in 38 | * troubleshooting and debugging failing tests. 39 | * 40 | * @author Max Saperstone 41 | * @version 3.3.1 42 | * @lastupdate 10/24/2019 43 | */ 44 | public class AssertExcludes extends Excludes { 45 | 46 | /** 47 | * The default constructor passing in the app and output file 48 | * 49 | * @param response - the response from the web services call 50 | * @param reporter - the file to write all logging out to 51 | */ 52 | public AssertExcludes(Response response, Reporter reporter) { 53 | this.response = response; 54 | this.reporter = reporter; 55 | } 56 | 57 | /////////////////////////////////////////////////////// 58 | // assertions about the page in general 59 | /////////////////////////////////////////////////////// 60 | 61 | /** 62 | * Asserts the actual response json payload contains each key provided, 63 | * and writes that to the output file. If this fails, the code will 64 | * immediately exit, and record the error. 65 | * 66 | * @param expectedKeys a list with string keys expected in the json 67 | * response 68 | */ 69 | @Override 70 | public void keys(List expectedKeys) { 71 | assertTrue(EXPECTED_NOT_TO_FIND + String.join(", ", expectedKeys), checkKeys(expectedKeys)); 72 | } 73 | 74 | /** 75 | * Asserts the actual response json payload contains each of the pair 76 | * values provided, and writes that to the output file. If this fails, the code will 77 | * immediately exit, and record the error. 78 | * 79 | * @param expectedPairs a hashmap with string key value pairs expected in the json 80 | * response 81 | */ 82 | @Override 83 | public void keyValues(Map expectedPairs) { 84 | assertTrue(EXPECTED_NOT_TO_FIND + Reporter.formatKeyPair(expectedPairs), checkKeyValues(expectedPairs)); 85 | } 86 | 87 | /** 88 | * Asserts the actual response json payload contains a key containing a JsonObject 89 | * excluding each of the keys provided. The jsonKeys should be passed in 90 | * as crumbs of the keys leading to the field with 91 | * the expected value. This result will be written out to the output file. 92 | * If this fails, the code will immediately exit, and record the error. 93 | * 94 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 95 | * @param expectedKeys - a list with string keys expected in the json 96 | * response 97 | */ 98 | @Override 99 | public void nestedKeys(List jsonKeys, List expectedKeys) { 100 | assertTrue(EXPECTED_NOT_TO_FIND + String.join(", " + expectedKeys), checkNestedKeys(jsonKeys, expectedKeys)); 101 | } 102 | 103 | /** 104 | * Asserts the actual response json payload contains a key containing a JsonObject 105 | * containing each of the pair values provided. The jsonKeys should be passed in 106 | * as crumbs of the keys leading to the field with 107 | * the expected value. This result will be written out to the output file. If this fails, the code will 108 | * immediately exit, and record the error. 109 | * 110 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 111 | * @param expectedPairs a hashmap with string key value pairs expected in the json 112 | * response 113 | */ 114 | @Override 115 | public void nestedKeyValues(List jsonKeys, Map expectedPairs) { 116 | assertTrue(EXPECTED_NOT_TO_FIND + Reporter.formatKeyPair(expectedPairs), checkNestedKeyValues(jsonKeys, expectedPairs)); 117 | } 118 | 119 | /** 120 | * Asserts the actual response json payload contains a key containing a JsonElement. 121 | * The jsonKeys should be passed in as crumbs of the keys leading to the field with 122 | * the expected value. This result will be written out to the output file. If this fails, the code will 123 | * immediately exit, and record the error. 124 | * 125 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 126 | * @param expectedJson - the expected response json array 127 | */ 128 | @Override 129 | public void nestedValue(List jsonKeys, JsonElement expectedJson) { 130 | assertTrue(EXPECTED_NOT_TO_FIND + GSON.toJson(expectedJson), checkNestedValue(jsonKeys, expectedJson)); 131 | } 132 | 133 | /** 134 | * Asserts the actual response json payload contains to the expected json 135 | * element, and writes that out to the output file. If this fails, the code will 136 | * immediately exit, and record the error. 137 | * 138 | * @param expectedJson - the expected response json array 139 | */ 140 | @Override 141 | public void value(JsonElement expectedJson) { 142 | assertTrue(EXPECTED_NOT_TO_FIND + GSON.toJson(expectedJson), checkValue(expectedJson)); 143 | } 144 | 145 | /** 146 | * Asserts the actual response json payload contains to the expected json 147 | * element, and writes that out to the output file. If this fails, the code will 148 | * immediately exit, and record the error. 149 | * 150 | * @param expectedMessage - the expected response json array 151 | */ 152 | @Override 153 | public void message(String expectedMessage) { 154 | assertTrue(EXPECTED_NOT_TO_FIND + "'" + expectedMessage + "'", checkMessage(expectedMessage)); 155 | } 156 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/services/check/AssertMatches.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.services.check; 22 | 23 | import com.coveros.selenified.services.Response; 24 | import com.coveros.selenified.utilities.Reporter; 25 | 26 | import java.util.List; 27 | 28 | import static com.coveros.selenified.utilities.Constants.DOES_NOT_MATCH_PATTERN; 29 | import static org.testng.AssertJUnit.assertTrue; 30 | 31 | /** 32 | * Assert will handle all verifications performed on the actual web services 33 | * calls themselves. These asserts are custom to the framework, and in addition to 34 | * providing easy object oriented capabilities, they assist in 35 | * troubleshooting and debugging failing tests. 36 | * 37 | * @author Max Saperstone 38 | * @version 3.3.1 39 | * @lastupdate 1/6/2020 40 | */ 41 | public class AssertMatches extends Matches { 42 | 43 | /** 44 | * The default constructor passing in the app and output file 45 | * 46 | * @param response - the response from the web services call 47 | * @param reporter - the file to write all logging out to 48 | */ 49 | public AssertMatches(Response response, Reporter reporter) { 50 | this.response = response; 51 | this.reporter = reporter; 52 | } 53 | 54 | /////////////////////////////////////////////////////// 55 | // assertions about the page in general 56 | /////////////////////////////////////////////////////// 57 | 58 | /** 59 | * Asserts the actual response code matches the expected response 60 | * code, and writes that out to the output file. If this fails, the code will 61 | * immediately exit, and record the error. 62 | * 63 | * @param expectedPattern - the expected pattern of the response code 64 | */ 65 | @Override 66 | public void code(String expectedPattern) { 67 | int code = checkCode(expectedPattern); 68 | assertTrue("Code Mismatch: code of '" + code + DOES_NOT_MATCH_PATTERN + expectedPattern + "'", String.valueOf(code).matches(expectedPattern)); 69 | } 70 | 71 | /** 72 | * Asserts the actual response json payload contains a key with a value matching the expected 73 | * value. The jsonKeys should be passed in as crumbs of the keys leading to the field with 74 | * the expected value. This result will be written out to the output file. If this fails, the code will 75 | * immediately exit, and record the error. 76 | * 77 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 78 | * @param expectedPattern - the expected pattern of the value 79 | */ 80 | @Override 81 | public void nestedValue(List jsonKeys, String expectedPattern) { 82 | String nestedValue = checkNestedValue(jsonKeys, expectedPattern); 83 | assertTrue("JsonElement Response Mismatch: nested value of '" + nestedValue + DOES_NOT_MATCH_PATTERN + expectedPattern + "'", nestedValue.matches(expectedPattern)); 84 | } 85 | 86 | /** 87 | * Asserts the actual response payload matches the expected 88 | * response payload, and writes that out to the output file. If this fails, the code will 89 | * immediately exit, and record the error. 90 | * 91 | * @param expectedPattern - the expected pattern of the message 92 | */ 93 | @Override 94 | public void message(String expectedPattern) { 95 | String message = checkMessage(expectedPattern); 96 | assertTrue("Response Message Mismatch: message of '" + message + DOES_NOT_MATCH_PATTERN + expectedPattern, message != null && message.matches(expectedPattern)); 97 | } 98 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/services/check/Matches.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.services.check; 22 | 23 | import com.coveros.selenified.utilities.Reporter; 24 | import com.google.gson.JsonElement; 25 | import com.google.gson.JsonObject; 26 | 27 | import java.util.List; 28 | 29 | import static com.coveros.selenified.utilities.Constants.*; 30 | 31 | /** 32 | * Contains will handle all checks performed on the actual web services 33 | * calls themselves involving whether or not the response has certain information. 34 | * These asserts are custom to the framework, and in addition to 35 | * providing easy object oriented capabilities, they assist in 36 | * troubleshooting and debugging failing tests. 37 | * 38 | * @author Max Saperstone 39 | * @version 3.3.1 40 | * @lastupdate 1/6/2020 41 | */ 42 | abstract class Matches extends Check { 43 | 44 | /** 45 | * Checks the actual response code is matching the expected response 46 | * code, and writes that out to the output file 47 | * 48 | * @param expectedPattern - the expected pattern of the response code 49 | */ 50 | abstract void code(String expectedPattern); 51 | 52 | /** 53 | * Checks the actual response code is matching the expected response 54 | * code, and writes that out to the output file 55 | * 56 | * @param expectedPattern - the expected pattern of the response code 57 | */ 58 | int checkCode(String expectedPattern) { 59 | int actualCode = this.response.getCode(); 60 | recordResult("Expected to find a response code matching a pattern of: '" + expectedPattern + ENDI, 61 | "Found a response code of " + actualCode + ENDB, String.valueOf(actualCode).matches(expectedPattern)); 62 | return actualCode; 63 | } 64 | 65 | /** 66 | * Checks the actual response json payload contains a key with a value matching the expected 67 | * value. The jsonKeys should be passed in as crumbs of the keys leading to the field with 68 | * the expected value. This result will be written out to the output file. 69 | * 70 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 71 | * @param expectedPattern - the expected pattern of the value 72 | */ 73 | abstract void nestedValue(List jsonKeys, String expectedPattern); 74 | 75 | /** 76 | * Checks the actual response json payload contains a key with a value matching the expected 77 | * value. The jsonCrumbs should be passed in as crumbs of the keys leading to the field with 78 | * the expected value. This result will be written out to the output file. 79 | * 80 | * @param jsonCrumbs - the crumbs of json object keys leading to the field with the expected value 81 | * @param expectedPattern - the expected pattern of the value 82 | */ 83 | String checkNestedValue(List jsonCrumbs, String expectedPattern) { 84 | JsonElement actualValue = this.response.getObjectData(); 85 | for (String jsonCrumb : jsonCrumbs) { 86 | if (!(actualValue instanceof JsonObject)) { 87 | actualValue = null; 88 | break; 89 | } 90 | actualValue = actualValue.getAsJsonObject().get(jsonCrumb); 91 | } 92 | String stringValue = String.valueOf(actualValue); 93 | if (actualValue != null) { 94 | try { 95 | stringValue = actualValue.getAsString(); 96 | } catch (UnsupportedOperationException e) { 97 | log.info(e); 98 | } 99 | } 100 | recordResult(EXPECTED_TO_FIND_A_RESPONSE_OF + STARTI + Reporter.formatHTML(String.join(ARROW, jsonCrumbs)) + ENDI + 101 | " matching a pattern of: " + DIV_I + expectedPattern + END_IDIV, 102 | FOUND + DIV_I + Reporter.formatHTML(GSON.toJson(actualValue)) + END_IDIV, stringValue.matches(expectedPattern)); 103 | return stringValue; 104 | } 105 | 106 | /** 107 | * Checks the actual response payload matches the expected 108 | * response payload, and writes that out to the output file 109 | * 110 | * @param expectedPattern - the expected pattern of the response message 111 | */ 112 | abstract void message(String expectedPattern); 113 | 114 | /** 115 | * Checks the actual response payload matches the expected 116 | * response payload, and writes that out to the output file 117 | * 118 | * @param expectedPattern - the expected pattern of the response message 119 | */ 120 | String checkMessage(String expectedPattern) { 121 | String actualMessage = this.response.getMessage(); 122 | recordResult(EXPECTED_TO_FIND_A_RESPONSE_MATCHING + STARTI + expectedPattern + ENDI, 123 | FOUND + STARTI + this.response.getMessage() + ENDI, actualMessage != null && actualMessage.matches(expectedPattern)); 124 | return actualMessage; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/services/check/VerifyContains.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.services.check; 22 | 23 | import com.coveros.selenified.services.Response; 24 | import com.coveros.selenified.utilities.Reporter; 25 | import com.google.gson.JsonElement; 26 | 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | /** 31 | * Verify will handle all verifications performed on the actual web services 32 | * calls themselves. These asserts are custom to the framework, and in addition to 33 | * providing easy object oriented capabilities, they assist in 34 | * troubleshooting and debugging failing tests. 35 | * 36 | * @author Max Saperstone 37 | * @version 3.3.1 38 | * @lastupdate 10/24/2019 39 | */ 40 | public class VerifyContains extends Contains { 41 | 42 | /** 43 | * The default constructor passing in the app and output file 44 | * 45 | * @param response - the response from the web services call 46 | * @param reporter - the file to write all logging out to 47 | */ 48 | public VerifyContains(Response response, Reporter reporter) { 49 | this.response = response; 50 | this.reporter = reporter; 51 | } 52 | 53 | /////////////////////////////////////////////////////// 54 | // assertions about the page in general 55 | /////////////////////////////////////////////////////// 56 | 57 | /** 58 | * Verifies the actual response json payload contains each key provided, 59 | * and writes that to the output file. 60 | * 61 | * @param expectedKeys a list with string keys expected in the json 62 | * response 63 | */ 64 | @Override 65 | public void keys(List expectedKeys) { 66 | checkKeys(expectedKeys); 67 | } 68 | 69 | /** 70 | * Verifies the actual response json payload contains each of the pair 71 | * values provided, and writes that to the output file. 72 | * 73 | * @param expectedPairs a hashmap with string key value pairs expected in the json 74 | * response 75 | */ 76 | @Override 77 | public void keyValues(Map expectedPairs) { 78 | checkKeyValues(expectedPairs); 79 | } 80 | 81 | /** 82 | * Verifies the actual response json payload contains to the expected json 83 | * element, and writes that out to the output file. 84 | * 85 | * @param expectedJson - the expected response json array 86 | */ 87 | @Override 88 | public void value(JsonElement expectedJson) { 89 | checkValue(expectedJson); 90 | } 91 | 92 | /** 93 | * Verifies the actual response json payload contains a key containing a JsonObject 94 | * containing each of the keys provided. The jsonKeys should be passed in 95 | * as crumbs of the keys leading to the field with 96 | * the expected value. This result will be written out to the output file. 97 | * 98 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 99 | * @param expectedKeys - a list with string keys expected in the json 100 | * response 101 | */ 102 | @Override 103 | public void nestedKeys(List jsonKeys, List expectedKeys) { 104 | checkNestedKeys(jsonKeys, expectedKeys); 105 | } 106 | 107 | /** 108 | * Verifies the actual response json payload contains a key containing a JsonObject 109 | * containing each of the pair values provided. The jsonKeys should be passed in 110 | * as crumbs of the keys leading to the field with 111 | * the expected value. This result will be written out to the output file. 112 | * 113 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 114 | * @param expectedPairs - a hashmap with string key value pairs expected in the json 115 | * response 116 | */ 117 | @Override 118 | public void nestedKeyValues(List jsonKeys, Map expectedPairs) { 119 | checkNestedKeyValues(jsonKeys, expectedPairs); 120 | } 121 | 122 | /** 123 | * Verifies the actual response json payload contains a key containing a JsonElement. 124 | * The jsonKeys should be passed in as crumbs of the keys leading to the field with 125 | * the expected value. This result will be written out to the output file. 126 | * 127 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 128 | * @param expectedJson - the expected response json array 129 | */ 130 | @Override 131 | public void nestedValue(List jsonKeys, JsonElement expectedJson) { 132 | checkNestedValue(jsonKeys, expectedJson); 133 | } 134 | 135 | /** 136 | * Verifies the actual response json payload contains to the expected json 137 | * element, and writes that out to the output file. 138 | * 139 | * @param expectedMessage - the expected response json array 140 | */ 141 | @Override 142 | public void message(String expectedMessage) { 143 | checkMessage(expectedMessage); 144 | } 145 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/services/check/VerifyEquals.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.services.check; 22 | 23 | import com.coveros.selenified.services.Response; 24 | import com.coveros.selenified.utilities.Reporter; 25 | import com.google.gson.JsonArray; 26 | import com.google.gson.JsonObject; 27 | 28 | import java.util.List; 29 | 30 | /** 31 | * Verify will handle all verifications performed on the actual web services 32 | * calls themselves. These asserts are custom to the framework, and in addition to 33 | * providing easy object oriented capabilities, they assist in 34 | * troubleshooting and debugging failing tests. 35 | * 36 | * @author Max Saperstone 37 | * @version 3.3.1 38 | * @lastupdate 10/24/2019 39 | */ 40 | public class VerifyEquals extends Equals { 41 | 42 | /** 43 | * The default constructor passing in the app and output file 44 | * 45 | * @param response - the response from the web services call 46 | * @param reporter - the file to write all logging out to 47 | */ 48 | public VerifyEquals(Response response, Reporter reporter) { 49 | this.response = response; 50 | this.reporter = reporter; 51 | } 52 | 53 | /////////////////////////////////////////////////////// 54 | // assertions about the page in general 55 | /////////////////////////////////////////////////////// 56 | 57 | /** 58 | * Verifies the actual response code is equals to the expected response 59 | * code, and writes that out to the output file. 60 | * 61 | * @param expectedCode - the expected response code 62 | */ 63 | @Override 64 | public void code(int expectedCode) { 65 | checkCode(expectedCode); 66 | } 67 | 68 | /** 69 | * Verifies the actual response json payload is equal to the expected 70 | * response json payload, and writes that out to the output file. 71 | * 72 | * @param expectedJson - the expected response json object 73 | */ 74 | @Override 75 | public void objectData(JsonObject expectedJson) { 76 | checkObjectData(expectedJson); 77 | } 78 | 79 | /** 80 | * Verifies the actual response json payload is equal to the expected 81 | * response json payload, and writes that out to the output file. 82 | * 83 | * @param expectedJson - the expected response json array 84 | */ 85 | @Override 86 | public void arrayData(JsonArray expectedJson) { 87 | checkArrayData(expectedJson); 88 | } 89 | 90 | /** 91 | * Verifies the actual response json payload contains a key with a value equal to the expected 92 | * value. The jsonKeys should be passed in as crumbs of the keys leading to the field with 93 | * the expected value. This result will be written out to the output file. 94 | * 95 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 96 | * @param expectedValue - the expected value 97 | */ 98 | @Override 99 | public void nestedValue(List jsonKeys, Object expectedValue) { 100 | checkNestedValue(jsonKeys, expectedValue); 101 | } 102 | 103 | /** 104 | * Verifies the actual response payload is equal to the expected 105 | * response payload, and writes that out to the output file. 106 | * 107 | * @param expectedMessage - the expected response message 108 | */ 109 | @Override 110 | public void message(String expectedMessage) { 111 | checkMessage(expectedMessage); 112 | } 113 | 114 | /** 115 | * Verifies the actual response payload contains the number of elements 116 | * in an array as expected, and writes that out to the output file. 117 | * 118 | * @param expectedSize - the expected array size 119 | */ 120 | @Override 121 | public void arraySize(int expectedSize) { 122 | checkArraySize(expectedSize); 123 | } 124 | 125 | /** 126 | * Verifies the actual response payload contains a key with a value of the number of elements 127 | * in an array as expected, and writes that out to the output file. 128 | * 129 | * @param expectedSize - the expected array size 130 | */ 131 | @Override 132 | public void nestedArraySize(List jsonKeys, int expectedSize) { 133 | checkNestedArraySize(jsonKeys, expectedSize); 134 | } 135 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/services/check/VerifyExcludes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.services.check; 22 | 23 | import com.coveros.selenified.services.Response; 24 | import com.coveros.selenified.utilities.Reporter; 25 | import com.google.gson.JsonElement; 26 | 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | /** 31 | * Verify will handle all verifications performed on the actual web services 32 | * calls themselves. These asserts are custom to the framework, and in addition to 33 | * providing easy object oriented capabilities, they assist in 34 | * troubleshooting and debugging failing tests. 35 | * 36 | * @author Max Saperstone 37 | * @version 3.3.1 38 | * @lastupdate 10/24/2019 39 | */ 40 | public class VerifyExcludes extends Excludes { 41 | 42 | /** 43 | * The default constructor passing in the app and output file 44 | * 45 | * @param response - the response from the web services call 46 | * @param reporter - the file to write all logging out to 47 | */ 48 | public VerifyExcludes(Response response, Reporter reporter) { 49 | this.response = response; 50 | this.reporter = reporter; 51 | } 52 | 53 | /////////////////////////////////////////////////////// 54 | // assertions about the page in general 55 | /////////////////////////////////////////////////////// 56 | 57 | /** 58 | * Verifies the actual response json payload contains each key provided, 59 | * and writes that to the output file. 60 | * 61 | * @param expectedKeys a list with string keys expected in the json 62 | * response 63 | */ 64 | @Override 65 | public void keys(List expectedKeys) { 66 | checkKeys(expectedKeys); 67 | } 68 | 69 | /** 70 | * Verifies the actual response json payload contains each of the pair 71 | * values provided, and writes that to the output file. 72 | * 73 | * @param expectedPairs a hashmap with string key value pairs expected in the json 74 | * response 75 | */ 76 | @Override 77 | public void keyValues(Map expectedPairs) { 78 | checkKeyValues(expectedPairs); 79 | } 80 | 81 | /** 82 | * Verifies the actual response json payload contains to the expected json 83 | * element, and writes that out to the output file. 84 | * 85 | * @param expectedJson - the expected response json array 86 | */ 87 | @Override 88 | public void value(JsonElement expectedJson) { 89 | checkValue(expectedJson); 90 | } 91 | 92 | /** 93 | * Verifies the actual response json payload contains a key containing a JsonObject 94 | * excluding each of the keys provided. The jsonKeys should be passed in 95 | * as crumbs of the keys leading to the field with 96 | * the expected value. This result will be written out to the output file. 97 | * 98 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 99 | * @param expectedKeys - a list with string keys expected in the json 100 | * response 101 | */ 102 | @Override 103 | public void nestedKeys(List jsonKeys, List expectedKeys) { 104 | checkNestedKeys(jsonKeys, expectedKeys); 105 | } 106 | 107 | /** 108 | * Verifies the actual response json payload contains a key containing a JsonObject 109 | * containing each of the pair values provided. The jsonKeys should be passed in 110 | * as crumbs of the keys leading to the field with 111 | * the expected value. This result will be written out to the output file. 112 | * 113 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 114 | * @param expectedPairs - a hashmap with string key value pairs expected in the json 115 | * response 116 | */ 117 | @Override 118 | public void nestedKeyValues(List jsonKeys, Map expectedPairs) { 119 | checkNestedKeyValues(jsonKeys, expectedPairs); 120 | } 121 | 122 | /** 123 | * Verifies the actual response json payload contains a key containing a JsonElement. 124 | * The jsonKeys should be passed in as crumbs of the keys leading to the field with 125 | * the expected value. This result will be written out to the output file. 126 | * 127 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 128 | * @param expectedJson - the expected response json array 129 | */ 130 | @Override 131 | public void nestedValue(List jsonKeys, JsonElement expectedJson) { 132 | checkNestedValue(jsonKeys, expectedJson); 133 | } 134 | 135 | /** 136 | * Verifies the actual response json payload contains to the expected json 137 | * element, and writes that out to the output file. 138 | * 139 | * @param expectedMessage - the expected response json array 140 | */ 141 | @Override 142 | public void message(String expectedMessage) { 143 | checkMessage(expectedMessage); 144 | } 145 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/services/check/VerifyMatches.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.services.check; 22 | 23 | import com.coveros.selenified.services.Response; 24 | import com.coveros.selenified.utilities.Reporter; 25 | 26 | import java.util.List; 27 | 28 | /** 29 | * Verify will handle all verifications performed on the actual web services 30 | * calls themselves. These asserts are custom to the framework, and in addition to 31 | * providing easy object oriented capabilities, they assist in 32 | * troubleshooting and debugging failing tests. 33 | * 34 | * @author Max Saperstone 35 | * @version 3.3.1 36 | * @lastupdate 1/6/2020 37 | */ 38 | public class VerifyMatches extends Matches { 39 | 40 | /** 41 | * The default constructor passing in the app and output file 42 | * 43 | * @param response - the response from the web services call 44 | * @param reporter - the file to write all logging out to 45 | */ 46 | public VerifyMatches(Response response, Reporter reporter) { 47 | this.response = response; 48 | this.reporter = reporter; 49 | } 50 | 51 | /////////////////////////////////////////////////////// 52 | // assertions about the page in general 53 | /////////////////////////////////////////////////////// 54 | 55 | /** 56 | * Verifies the actual response code matches the expected response 57 | * code, and writes that out to the output file. 58 | * 59 | * @param expectedPattern - the expected pattern of the response code 60 | */ 61 | @Override 62 | public void code(String expectedPattern) { 63 | checkCode(expectedPattern); 64 | } 65 | 66 | /** 67 | * Verifies the actual response json payload contains a key with a value matching the expected 68 | * value. The jsonKeys should be passed in as crumbs of the keys leading to the field with 69 | * the expected value. This result will be written out to the output file. 70 | * 71 | * @param jsonKeys - the crumbs of json object keys leading to the field with the expected value 72 | * @param expectedPattern - the expected pattern of the value 73 | */ 74 | @Override 75 | public void nestedValue(List jsonKeys, String expectedPattern) { 76 | checkNestedValue(jsonKeys, expectedPattern); 77 | } 78 | 79 | /** 80 | * Verifies the actual response payload matches the expected 81 | * response payload, and writes that out to the output file. 82 | * 83 | * @param expectedPattern - the expected pattern of the response message 84 | */ 85 | @Override 86 | public void message(String expectedPattern) { 87 | checkMessage(expectedPattern); 88 | } 89 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/utilities/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.utilities; 22 | 23 | import com.google.gson.Gson; 24 | import com.google.gson.GsonBuilder; 25 | 26 | /** 27 | * Constants simply holds constant variables to be used through out the application for checks 28 | * 29 | * @author Max Saperstone 30 | * @version 3.3.1 31 | * @lastupdate 1/6/2020 32 | */ 33 | public class Constants { 34 | 35 | public static final String OF = "of "; 36 | public static final String ON_PAGE = " on the page"; 37 | public static final String NO_ALERT = "An alert is not present on the page"; 38 | public static final String ALERT_TEXT = "An alert with text "; 39 | public static final String NO_CONFIRMATION = "A confirmation is not present on the page"; 40 | public static final String CONFIRMATION_TEXT = "A confirmation with text "; 41 | public static final String NO_PROMPT = "A prompt is not present on the page"; 42 | public static final String PROMPT_TEXT = "A prompt with text "; 43 | public static final String STORED = " is stored for the page"; 44 | public static final String NOT_STORED = " is not stored for the page"; 45 | public static final String VALUE_OF = " and a value of "; 46 | public static final String COOKIE = "A cookie with the name "; 47 | public static final String TEXT_B = "The text "; 48 | public static final String B_PRESENT = " is present on the page"; 49 | public static final String CLASS = "class"; 50 | public static final String HAS_VALUE = " has the value of "; 51 | public static final String HAS_TEXT = " has the text of "; 52 | public static final String HAS_OPTION = " has the option of "; 53 | public static final String CONTAINS_VALUE = " contains the value of "; 54 | public static final String EXCLUDES_VALUE = " does not contain the value of "; 55 | public static final String CONTAINS_TEXT = " contains the text of "; 56 | public static final String EXCLUDES_TEXT = " does not contain the text of "; 57 | public static final String ONLY_VALUE = ", only the values "; 58 | public static final String CLASS_VALUE = " has a class value of "; 59 | public static final String IS_NOT_INPUT = " is not an input on the page"; 60 | public static final String IS_NOT_SELECT = " is not a select on the page"; 61 | public static final String IS_NOT_TABLE = " is not a table on the page"; 62 | public static final String IS_PRESENT = " is present on the page"; 63 | public static final String IS_NOT_PRESENT = " is not present on the page"; 64 | public static final String IS_DISPLAYED = " is displayed on the page"; 65 | public static final String IS_NOT_DISPLAYED = " is not displayed on the page"; 66 | public static final String IS_CHECKED = " is checked on the page"; 67 | public static final String IS_NOT_CHECKED = " is not checked on the page"; 68 | public static final String IS_EDITABLE = " is editable on the page"; 69 | public static final String IS_NOT_EDITABLE = " is not editable on the page"; 70 | public static final String IS_ENABLED = " is enabled on the page"; 71 | public static final String IS_NOT_ENABLED = " is not enabled on the page"; 72 | public static final String MATCH_PATTERN = " text to match a pattern of "; 73 | public static final String OPTIONS = " has options of "; 74 | public static final String VALUES = " has values of "; 75 | public static final String WITH = " with the value of "; 76 | public static final String NO_ELEMENT_FOUND = "No element found"; 77 | public static final String ELEMENT_NOT_PRESENT = "Element not present"; 78 | public static final String ELEMENT_NOT_SELECT = "Element not select"; 79 | public static final String ELEMENT_NOT_TABLE = "Element not table"; 80 | public static final String CELL_OUT_OF_BOUNDS = "Cell out of bounds"; 81 | public static final String CONTAINS = "' contains '"; 82 | public static final String DOES_NOT_MATCH_PATTERN = "' doesn't match pattern '"; 83 | public static final String DOES_NOT_CONTAIN = "' doesn't contain '"; 84 | public static final String EXPECTED_ELEMENT_NOT_PRESENT = "Expected Element Not Present"; 85 | 86 | public static final String EXPECTED_TO_FIND_A_RESPONSE_OF = "Expected to find a response of: "; 87 | public static final String EXPECTED_TO_FIND_A_RESPONSE_CONTAINING = "Expected to find a response containing: "; 88 | public static final String EXPECTED_TO_FIND_A_RESPONSE_EXCLUDING = "Expected to find a response excluding: "; 89 | public static final String EXPECTED_TO_FIND_A_RESPONSE_MATCHING = "Expected to find a response matching a pattern of: "; 90 | public static final String EXPECTED_TO_FIND = "Expected to find "; 91 | public static final String EXPECTED_NOT_TO_FIND = "Expected not to find "; 92 | public static final String CONTAINING = " containing: "; 93 | public static final String EXCLUDING = " excluding: "; 94 | public static final String FOUND = "Found a response of: "; 95 | public static final String STARTI = "'"; 96 | public static final String ENDI = "'"; 97 | public static final String STARTB = ""; 98 | public static final String ENDB = ""; 99 | public static final String DIV_I = "
"; 100 | public static final String END_IDIV = "
"; 101 | 102 | static final String LINK_START = ""; 104 | static final String LINK_END = ""; 105 | 106 | public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); 107 | 108 | private Constants() { 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/utilities/Hub.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.utilities; 22 | 23 | import com.coveros.selenified.exceptions.InvalidHubException; 24 | 25 | import java.net.MalformedURLException; 26 | import java.net.URL; 27 | 28 | import static com.coveros.selenified.utilities.Property.HUB; 29 | import static com.coveros.selenified.utilities.Property.getProgramProperty; 30 | 31 | /** 32 | * Utilities class to interact with some remote hub driver, retrieving information such as username, key, and test status 33 | * 34 | * @author Max Saperstone 35 | * @version 3.3.1 36 | * @lastupdate 8/23/2019 37 | */ 38 | public class Hub { 39 | 40 | private static final String HUB_ISN_T_SET = "Hub isn't set"; 41 | private static final String HUB_USER = "HUB_USER"; 42 | private static final String HUB_PASS = "HUB_PASS"; 43 | private URL hubURL; 44 | private String username = null; 45 | private String password = null; 46 | 47 | public Hub() throws MalformedURLException { 48 | if (!isHubSet()) { 49 | throw new InvalidHubException(HUB_ISN_T_SET); 50 | } 51 | String hubProperty = getProgramProperty(HUB); 52 | try { 53 | this.hubURL = new URL(hubProperty); 54 | } catch (MalformedURLException e) { 55 | throw new InvalidHubException("Hub '" + hubProperty + "' isn't valid. Must contain protocol, optionally credentials, and endpoint"); 56 | } 57 | setUserInfo(); 58 | String credentials = username == null ? "" : username + ":" + password + "@"; 59 | String port = hubURL.getPort() == -1 ? "" : ":" + hubURL.getPort(); 60 | this.hubURL = new URL(hubURL.getProtocol() + "://" + credentials + hubURL.getHost() + port + hubURL.getFile() + "/wd/hub"); 61 | } 62 | 63 | /** 64 | * Determines if a hub property is set. This could be to sauce, grid, or any other cloud tool. 65 | * This should be provided with the protocol and address, but leaving out the /wd/hub 66 | * 67 | * @return boolean: is a hub location set 68 | */ 69 | public static boolean isHubSet() { 70 | String hub = getProgramProperty(HUB); 71 | return hub != null && !"".equals(hub); 72 | } 73 | 74 | private void setUserInfo() throws InvalidHubException { 75 | String userInfo = hubURL.getUserInfo(); 76 | if (System.getenv(HUB_USER) != null && System.getenv(HUB_PASS) != null) { 77 | this.username = System.getenv(HUB_USER); 78 | this.password = System.getenv(HUB_PASS); 79 | } else if (userInfo != null) { 80 | int split = userInfo.indexOf(':'); 81 | if (split >= 0 && split <= userInfo.length()) { 82 | this.username = userInfo.substring(0, split); 83 | this.password = userInfo.substring(split + 1); 84 | } else { 85 | throw new InvalidHubException("Hub isn't valid. Credentials '" + userInfo + "' must contain both username and password"); 86 | } 87 | } 88 | } 89 | 90 | /** 91 | * Retrieves the hub property if it is set. This could be to sauce, grid, or any other cloud tool. 92 | * This should be provided with the protocol and address, but leaving out the /wd/hub 93 | * 94 | * @return String: the set hub address, null if none are set 95 | */ 96 | public URL getHubURL() { 97 | return hubURL; 98 | } 99 | 100 | public String getUsername() { 101 | return username; 102 | } 103 | 104 | public String getPassword() { 105 | return password; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/utilities/LambdaTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.utilities; 22 | 23 | import com.coveros.selenified.services.HTTP; 24 | import com.coveros.selenified.services.Request; 25 | import com.google.gson.JsonObject; 26 | import org.testng.ITestResult; 27 | import org.testng.log4testng.Logger; 28 | 29 | import java.io.IOException; 30 | import java.net.MalformedURLException; 31 | 32 | import static com.coveros.selenified.Selenified.SESSION_ID; 33 | import static com.coveros.selenified.utilities.Property.HUB; 34 | import static com.coveros.selenified.utilities.Property.getProgramProperty; 35 | 36 | /** 37 | * Utilities class to interact with lambda test, retrieving information such as username, key, and test status 38 | * 39 | * @author Max Saperstone 40 | * @version 3.3.1 41 | * @lastupdate 8/18/2019 42 | */ 43 | public class LambdaTest extends Hub { 44 | private static final Logger log = Logger.getLogger(LambdaTest.class); 45 | 46 | public LambdaTest() throws MalformedURLException { 47 | super(); 48 | } 49 | 50 | /** 51 | * Determine whether the hub parameter is set, and if it is, is it set to sauce labs? Iff, then will return true, 52 | * otherwise, returns false 53 | * 54 | * @return Boolean: whether sauce labs is specified as the hub 55 | */ 56 | public static Boolean isLambdaTest() { 57 | String hub = getProgramProperty(HUB); 58 | return hub != null && hub.contains("hub.lambdatest.com"); 59 | } 60 | 61 | /** 62 | * Connects with Lambda Test and updates the status in their system to the test result 63 | * status 64 | * 65 | * @param result - the testng itestresult object 66 | */ 67 | static void updateStatus(ITestResult result) { 68 | if (isLambdaTest() && result.getAttributeNames().contains(SESSION_ID)) { 69 | String sessionId = result.getAttribute(SESSION_ID).toString(); 70 | JsonObject json = new JsonObject(); 71 | String status = (result.getStatus() == 1) ? "passed" : "failed"; 72 | json.addProperty("status_ind", status); 73 | try { 74 | LambdaTest lambdaTest = new LambdaTest(); 75 | HTTP http = new HTTP(null, "https://api.lambdatest.com/automation/api/v1/", lambdaTest.getUsername(), lambdaTest.getPassword()); 76 | http.patch("sessions/" + sessionId, new Request().setJsonPayload(json), null); 77 | } catch (MalformedURLException e) { 78 | log.error("Unable to connect to lambda test, due to credential problems"); 79 | } catch (IOException e) { 80 | log.error(e); 81 | } 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/utilities/Sauce.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.utilities; 22 | 23 | import com.coveros.selenified.exceptions.InvalidSauceException; 24 | import com.saucelabs.saucerest.SauceException; 25 | import com.saucelabs.saucerest.SauceREST; 26 | import org.openqa.selenium.remote.DesiredCapabilities; 27 | import org.testng.ITestResult; 28 | import org.testng.log4testng.Logger; 29 | 30 | import java.net.MalformedURLException; 31 | 32 | import static com.coveros.selenified.Selenified.SESSION_ID; 33 | import static com.coveros.selenified.utilities.Property.HUB; 34 | import static com.coveros.selenified.utilities.Property.getProgramProperty; 35 | 36 | /** 37 | * Utilities class to interact with sauce labs, retrieving information such as username, key, and test status 38 | * 39 | * @author Max Saperstone 40 | * @version 3.3.1 41 | * @lastupdate 8/18/2019 42 | */ 43 | public class Sauce extends Hub { 44 | private static final Logger log = Logger.getLogger(Sauce.class); 45 | private static final String SAUCE_HUB_ISN_T_SET = "Sauce hub isn't set"; 46 | 47 | public Sauce() throws MalformedURLException { 48 | super(); 49 | } 50 | 51 | /** 52 | * Determine whether the hub parameter is set, and if it is, is it set to sauce labs? Iff, then will return true, 53 | * otherwise, returns false 54 | * 55 | * @return Boolean: whether sauce labs is specified as the hub 56 | */ 57 | public static Boolean isSauce() { 58 | String hub = getProgramProperty(HUB); 59 | return hub != null && hub.contains("ondemand.saucelabs.com"); 60 | } 61 | 62 | /** 63 | * Connects with SauceLabs and updates the status in their system to the test result 64 | * status 65 | * 66 | * @param result - the testng itestresult object 67 | */ 68 | static void updateStatus(ITestResult result) { 69 | if (isSauce() && result.getAttributeNames().contains(SESSION_ID)) { 70 | String sessionId = result.getAttribute(SESSION_ID).toString(); 71 | try { 72 | SauceREST sauce = new Sauce().getSauceConnection(); 73 | if (result.getStatus() == 1) { 74 | sauce.jobPassed(sessionId); 75 | } else { 76 | sauce.jobFailed(sessionId); 77 | } 78 | } catch (SauceException | MalformedURLException e) { 79 | log.error("Unable to connect to sauce, due to credential problems"); 80 | } 81 | } 82 | } 83 | 84 | /** 85 | * Sauce labs has specific capabilities to manage the selenium version used. The version is obtained from the 86 | * POM (or could be passed in via CMD to override) and then set so that Sauce sets the specific selenium version, 87 | * instead of their default: https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options#TestConfigurationOptions-SeleniumVersion 88 | * Additionally, the iedriverVersion is set to match the selenium version as suggested, if ie is the chosen browser 89 | * Finally, the default platform for edge is set to windows 10 90 | */ 91 | public static void setupSauceCapabilities(DesiredCapabilities desiredCapabilities) { 92 | if (Sauce.isSauce()) { 93 | // set the selenium version 94 | desiredCapabilities.setCapability("seleniumVersion", System.getProperty("selenium.version")); 95 | // set the ie driver if needed 96 | if (desiredCapabilities.getBrowserName().equals("internet explorer")) { 97 | desiredCapabilities.setCapability("iedriverVersion", System.getProperty("selenium.version")); 98 | } 99 | } 100 | } 101 | 102 | /** 103 | * Creates a new connection to sauce labs 104 | * 105 | * @return SauceREST: an object with information to connect to/update sauce labs 106 | * @throws MalformedURLException if no sauce connection is set, invalid hub will be thrown 107 | */ 108 | public SauceREST getSauceConnection() throws MalformedURLException { 109 | if (!isSauce()) { 110 | throw new InvalidSauceException(SAUCE_HUB_ISN_T_SET); 111 | } 112 | return new SauceREST(getUsername(), getPassword()); 113 | } 114 | } -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/utilities/TestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.utilities; 22 | 23 | import java.lang.reflect.Method; 24 | import java.util.Random; 25 | 26 | /** 27 | * Manages the test cases, including naming conventions and formatting 28 | * 29 | * @author Max Saperstone 30 | * @version 3.3.1 31 | * @lastupdate 6/28/2019 32 | */ 33 | public class TestCase { 34 | 35 | private TestCase() { 36 | } 37 | 38 | //constants 39 | private static final int MAXFILENAMELENGTH = 200; 40 | 41 | /** 42 | * Generates a random string of alpha-numeric characters 43 | * 44 | * @param length the length of the random string 45 | * @return String: random string of characters 46 | */ 47 | public static String getRandomString(int length) { 48 | if (length <= 0) { 49 | return ""; 50 | } 51 | String stringChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 52 | Random rnd = new Random(); 53 | StringBuilder sb = new StringBuilder(length); 54 | for (int i = 0; i < length; i++) { 55 | sb.append(stringChars.charAt(rnd.nextInt(stringChars.length()))); 56 | } 57 | return sb.toString(); 58 | } 59 | 60 | /** 61 | * Removes all non alphanumeric characters from a provided string 62 | * 63 | * @param value - the string to cleanup 64 | * @return String: the provided string with all alphanumeric characters 65 | * removed 66 | */ 67 | public static String removeNonWordCharacters(String value) { 68 | if (value == null) { 69 | return null; 70 | } 71 | return value.replaceAll("[^a-zA-Z0-9]+", ""); 72 | } 73 | 74 | /** 75 | * Determines the unique test name, based on the parameters passed in 76 | * 77 | * @param method - the method under test to extract the name from 78 | * @param dataProvider - an array of objects being passed to the test as data 79 | * providers 80 | * @return String: a unique name 81 | */ 82 | public static String getTestName(Method method, Object... dataProvider) { 83 | //TODO - look at making use of new setTestName and getFactoryParameters 84 | return getTestName(method.getDeclaringClass().getName(), method.getName(), dataProvider); 85 | } 86 | 87 | /** 88 | * Determines the unique test name, based on the parameters passed in 89 | * 90 | * @param className - the class name of the test method as a string 91 | * @param methodName - the method name of the test as a string 92 | * @param dataProvider - an array of objects being passed to the test as data 93 | * providers 94 | * @return String: a unique name 95 | */ 96 | @SuppressWarnings("squid:S2116") 97 | public static String getTestName(String className, String methodName, Object... dataProvider) { 98 | StringBuilder testName = new StringBuilder(className + "." + methodName); 99 | if (dataProvider != null && dataProvider.length > 0) { 100 | addParameters(testName, dataProvider); 101 | if (testName.toString().length() > MAXFILENAMELENGTH) { 102 | testName = new StringBuilder(className + "." + methodName + dataProvider.toString().split(";")[1]); 103 | // purposefully using toString on object to obtain unique random hash 104 | } 105 | } 106 | return testName.toString(); 107 | } 108 | 109 | /** 110 | * Loops through dataProviders, and adds string value of each one to test case name 111 | * 112 | * @param testName - StringBuilder containing the test case name 113 | * @param dataProvider - an array of objects being passed to the test as data 114 | * providers 115 | */ 116 | static void addParameters(StringBuilder testName, Object[] dataProvider) { 117 | StringBuilder stringBuilder = new StringBuilder(); 118 | for (Object data : dataProvider) { 119 | if (data == null) { 120 | continue; 121 | } 122 | stringBuilder.append(Reporter.capitalizeFirstLetters(removeNonWordCharacters(data.toString()))); 123 | } 124 | if(stringBuilder.length() > 0) { 125 | testName.append("WithOption").append(stringBuilder); 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/com/coveros/selenified/utilities/Transformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Coveros, Inc. 3 | * 4 | * This file is part of Selenified. 5 | * 6 | * Selenified is licensed under the Apache License, Version 7 | * 2.0 (the "License"); you may not use this file except 8 | * in compliance with the License. You may obtain a copy 9 | * of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on 15 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | */ 20 | 21 | package com.coveros.selenified.utilities; 22 | 23 | import org.apache.commons.lang3.StringUtils; 24 | import org.testng.annotations.ITestAnnotation; 25 | import org.testng.internal.annotations.IAnnotationTransformer; 26 | 27 | import java.lang.reflect.Constructor; 28 | import java.lang.reflect.Method; 29 | 30 | import static com.coveros.selenified.utilities.Property.getBrowser; 31 | 32 | /** 33 | * Programmatically sets an invocation count for each test, based on the number 34 | * of browsers desired to test on. This allows for simple looping of the same 35 | * test multiple times each run on a different browser, which is handled by the 36 | * Selenified class. This class should be specified as a listener for the main 37 | * Selenified class, and/or in the TestNG xml file. 38 | * 39 | * @author Max Saperstone 40 | * @version 3.3.1 41 | * @lastupdate 8/29/2018 42 | */ 43 | public class Transformer implements IAnnotationTransformer { 44 | 45 | /** 46 | * overrides the basic TestNG transform function to provide dynamic access 47 | * to an invocation count 48 | */ 49 | @SuppressWarnings("rawtypes") 50 | @Override 51 | public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { 52 | annotation.setInvocationCount(StringUtils.countMatches(getBrowser(), ",") + 1); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/ConflictIT.java: -------------------------------------------------------------------------------- 1 | import com.coveros.selenified.Locator; 2 | import com.coveros.selenified.Selenified; 3 | import com.coveros.selenified.application.App; 4 | import com.coveros.selenified.element.Element; 5 | import integration.WebBase; 6 | import org.testng.ITestContext; 7 | import org.testng.annotations.BeforeClass; 8 | import org.testng.annotations.Test; 9 | 10 | public class ConflictIT extends WebBase { 11 | 12 | @Test(groups = {"integration", "conflict"}, 13 | description = "A sample test to show how to loop through elements with multiple matches") 14 | public void conflictingTestName() { 15 | // use this object to manipulate the app 16 | App app = this.apps.get(); 17 | // perform some actions 18 | Element element = app.newElement(Locator.XPATH, "//form/input[@type='checkbox']"); 19 | for (int match = 0; match < element.get().matchCount(); match++) { 20 | element.setMatch(match); 21 | element.click(); 22 | element.assertState().checked(); 23 | } 24 | // close out the test 25 | finish(); 26 | } 27 | } -------------------------------------------------------------------------------- /src/test/java/TestCaseTest.java: -------------------------------------------------------------------------------- 1 | import com.coveros.selenified.utilities.TestCase; 2 | import org.testng.annotations.Test; 3 | 4 | import java.lang.reflect.Method; 5 | 6 | import static org.testng.Assert.assertEquals; 7 | 8 | public class TestCaseTest { 9 | @Test 10 | public void getTestNameTest(Method method) { 11 | assertEquals(TestCase.getTestName(method), "TestCaseTest.getTestNameTest"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/integration/ConflictIT.java: -------------------------------------------------------------------------------- 1 | package integration; 2 | 3 | import com.coveros.selenified.Locator; 4 | import com.coveros.selenified.application.App; 5 | import com.coveros.selenified.element.Element; 6 | import org.testng.annotations.Test; 7 | 8 | @Test(groups = {"conflict full"}) 9 | public class ConflictIT extends WebBase { 10 | 11 | @Test(groups = {"integration", "conflict"}, 12 | description = "A sample test to show how to loop through elements with multiple matches") 13 | public void conflictingTestName() { 14 | // use this object to manipulate the app 15 | App app = this.apps.get(); 16 | // perform some actions 17 | Element element = app.newElement(Locator.XPATH, "//form/input[@type='checkbox']"); 18 | for (int match = 0; match < element.get().matchCount(); match++) { 19 | element.setMatch(match); 20 | element.click(); 21 | element.assertState().checked(); 22 | } 23 | // close out the test 24 | finish(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/integration/NoBrowserIT.java: -------------------------------------------------------------------------------- 1 | package integration; 2 | 3 | import com.coveros.selenified.application.App; 4 | import org.testng.ITestContext; 5 | import org.testng.ITestResult; 6 | import org.testng.annotations.BeforeMethod; 7 | import org.testng.annotations.Test; 8 | 9 | import java.io.IOException; 10 | import java.lang.reflect.Method; 11 | 12 | import static com.coveros.selenified.Browser.BrowserUse; 13 | import static org.testng.Assert.assertNull; 14 | 15 | public class NoBrowserIT extends WebBase { 16 | 17 | @BeforeMethod(alwaysRun = true) 18 | protected void startTest(Object[] dataProvider, Method method, ITestContext test, ITestResult result) throws IOException { 19 | super.startTest(dataProvider, method, test, result, BrowserUse.FALSE); 20 | } 21 | 22 | @Test(groups = {"integration"}, description = "An integration test to verify we can start a test without a browser") 23 | public void verifyNoBrowser() { 24 | // use this object to manipulate the app 25 | App app = this.apps.get(); 26 | // verify no selenium actions class was setup 27 | assertNull(app); 28 | // verify no issues 29 | finish(); 30 | } 31 | } -------------------------------------------------------------------------------- /src/test/java/integration/NoJavascriptIT.java: -------------------------------------------------------------------------------- 1 | package integration; 2 | 3 | import com.coveros.selenified.Locator; 4 | import com.coveros.selenified.application.App; 5 | import org.testng.ITestContext; 6 | import org.testng.annotations.BeforeClass; 7 | import org.testng.annotations.Test; 8 | 9 | public class NoJavascriptIT extends WebBase { 10 | 11 | @BeforeClass(alwaysRun = true) 12 | public void beforeClass(ITestContext test) { 13 | addAdditionalDesiredCapabilities(this, test, "javascriptEnabled", false); 14 | super.beforeClass(test); 15 | } 16 | 17 | @Test(groups = {"integration", "assert", "excludes"}, 18 | description = "An integration test to check the checkElementDoesntHaveAttribute method") 19 | public void checkElementDoesntHaveAnyAttributeTest() { 20 | // use this object to manipulate the app 21 | App app = this.apps.get(); 22 | // perform some actions 23 | app.newElement(Locator.TAGNAME, "body").assertExcludes().attribute("class"); 24 | // verify no issues 25 | finish(); 26 | } 27 | 28 | @Test(groups = {"integration", "assert", "contains"}, 29 | description = "An integration test to check the checkElementDoesntHaveAttribute method", expectedExceptions = AssertionError.class) 30 | public void checkElementDoesHaveAnAttributeTest() { 31 | // use this object to manipulate the app 32 | App app = this.apps.get(); 33 | // perform some actions 34 | app.newElement(Locator.TAGNAME, "body").assertContains().attribute("class"); 35 | // verify one issue 36 | finish(1); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/integration/NoLoadIT.java: -------------------------------------------------------------------------------- 1 | package integration; 2 | 3 | import com.coveros.selenified.Browser.BrowserUse; 4 | import com.coveros.selenified.application.App; 5 | import com.coveros.selenified.utilities.Property; 6 | import org.apache.commons.io.FileUtils; 7 | import org.testng.ITestContext; 8 | import org.testng.ITestResult; 9 | import org.testng.annotations.BeforeMethod; 10 | import org.testng.annotations.Test; 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.lang.reflect.Method; 15 | 16 | import static org.testng.Assert.assertFalse; 17 | import static org.testng.Assert.assertNotNull; 18 | 19 | public class NoLoadIT extends WebBase { 20 | 21 | @BeforeMethod(alwaysRun = true) 22 | protected void startTest(Object[] dataProvider, Method method, ITestContext test, ITestResult result) throws IOException { 23 | super.startTest(dataProvider, method, test, result, BrowserUse.OPEN); 24 | } 25 | 26 | @SuppressWarnings("deprecation") 27 | @Test(groups = {"integration"}, 28 | description = "An integration test to verify we can start a test with a browser, but won't load any app") 29 | public void verifyNoLoad(ITestContext context) throws IOException { 30 | // use this object to manipulate the app 31 | App app = this.apps.get(); 32 | // verify a selenium actions class was setup 33 | assertNotNull(app); 34 | String directory = context.getOutputDirectory(); 35 | String file = app.getReporter().getFileName(); 36 | assertFalse(FileUtils.readFileToString(new File(directory, file + ".html")) 37 | .contains("Opening new browser and loading up starting app")); 38 | // verify the app wasn't attempted to load 39 | app.verify().urlEquals(Property.getAppURL(this.getClass().getName(), context)); 40 | // verify one issue from the above check 41 | finish(1); 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/java/integration/OverrideIT.java: -------------------------------------------------------------------------------- 1 | package integration; 2 | 3 | import com.coveros.selenified.Browser; 4 | import com.coveros.selenified.Locator; 5 | import com.coveros.selenified.application.App; 6 | import com.coveros.selenified.element.Element; 7 | import org.openqa.selenium.remote.DesiredCapabilities; 8 | import org.testng.ITestContext; 9 | import org.testng.annotations.BeforeClass; 10 | import org.testng.annotations.Test; 11 | 12 | import static org.testng.Assert.assertFalse; 13 | 14 | public class OverrideIT extends WebBase { 15 | 16 | @BeforeClass(alwaysRun = true) 17 | public void beforeClass(ITestContext test) { 18 | addAdditionalDesiredCapabilities(this, test, "javascriptEnabled", false); 19 | super.beforeClass(test); 20 | } 21 | 22 | @Test(groups = {"integration", "selenified", "override"}, 23 | description = "An integration test to check that properties can be overridden") 24 | public void overrideTest() { 25 | // use this object to manipulate the app 26 | App app = this.apps.get(); 27 | // perform some actions 28 | Element table = app.newElement(Locator.ID, "table"); 29 | if (app.getBrowser().getName() == Browser.BrowserName.HTMLUNIT) { 30 | table.verifyExcludes().attribute("id"); 31 | // verify no issues 32 | finish(); 33 | } else { 34 | table.assertContains().attribute("id"); 35 | // verify no issues 36 | finish(); 37 | } 38 | } 39 | 40 | @Test(groups = {"integration", "selenified", "override"}, 41 | description = "An integration test to check that properties can be overridden") 42 | public void overrideVarCheckTest() { 43 | // use this object to manipulate the app 44 | App app = this.apps.get(); 45 | // perform some actions 46 | DesiredCapabilities desiredCapabilities = app.getDesiredCapabilities(); 47 | assertFalse(app.getDesiredCapabilities().isJavascriptEnabled()); 48 | // verify no issues 49 | finish(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/integration/SelenifiedIT.java: -------------------------------------------------------------------------------- 1 | package integration; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | public class SelenifiedIT extends WebBase { 6 | 7 | @Test 8 | public void noAnnotationDetailsTest() { 9 | // verify no issues 10 | finish(); 11 | } 12 | 13 | @Test(groups = {"integration", "selenified"}) 14 | public void noDescriptionTest() { 15 | // verify no issues 16 | finish(); 17 | } 18 | 19 | @Test(description = "A test to verify that logs work without any groups") 20 | public void noGroupsTest() { 21 | // verify no issues 22 | finish(); 23 | } 24 | 25 | @Test(groups = "integration") 26 | public void oneGroupTest() { 27 | // verify no issues 28 | finish(); 29 | } 30 | 31 | @Test(groups = {"integration", "selenified", "no-htmlunit", "no-chrome", "no-edge", "no-firefox", "no-safari", "no-internetexplorer"}, 32 | description = "A test to verify a skip is thrown") 33 | public void skipThisTest() { 34 | this.apps.get().getReporter().fail("", "", ""); 35 | finish(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/integration/ServicesErrorIT.java: -------------------------------------------------------------------------------- 1 | package integration; 2 | 3 | import com.coveros.selenified.Browser.BrowserUse; 4 | import com.coveros.selenified.Selenified; 5 | import com.coveros.selenified.services.Call; 6 | import com.coveros.selenified.services.Request; 7 | import org.testng.ITestContext; 8 | import org.testng.ITestResult; 9 | import org.testng.annotations.BeforeClass; 10 | import org.testng.annotations.BeforeMethod; 11 | import org.testng.annotations.Test; 12 | 13 | import java.io.IOException; 14 | import java.lang.reflect.Method; 15 | 16 | public class ServicesErrorIT extends Selenified { 17 | 18 | @BeforeClass(alwaysRun = true) 19 | public void beforeClass(ITestContext test) { 20 | // set the base URL for the tests here 21 | setAppURL(this, test, "https://google.com/"); 22 | // set the author of the tests here 23 | setAuthor(this, test, "Max Saperstone\n
max.saperstone@coveros.com"); 24 | // set the version of the tests or of the software, possibly with a 25 | // dynamic check 26 | setVersion(this, test, "3.3.1"); 27 | } 28 | 29 | @BeforeMethod(alwaysRun = true) 30 | protected void startTest(Object[] dataProvider, Method method, ITestContext test, ITestResult result) throws IOException { 31 | super.startTest(dataProvider, method, test, result, BrowserUse.FALSE); 32 | } 33 | 34 | @Test(groups = {"integration", "service", "httpget", "https"}, 35 | description = "An integration test to verify the response code from a get call") 36 | public void compareGetResponseCode200Test() { 37 | // use this object to make calls 38 | Call call = this.calls.get(); 39 | // perform some actions 40 | call.get("posts/4").verifyEquals().code(200); 41 | // verify 1 issue 42 | finish(1); 43 | } 44 | 45 | @Test(groups = {"integration", "service", "httppost", "https"}, 46 | description = "An integration test to verify the response code from a post call") 47 | public void comparePostResponseCode201Test() { 48 | // use this object to verify the app looks as expected 49 | Call call = this.calls.get(); 50 | // perform some actions 51 | call.post("posts/", new Request()).verifyEquals().code(201); 52 | // verify 1 issue 53 | finish(1); 54 | } 55 | 56 | @Test(groups = {"integration", "service", "httpput", "https"}, 57 | description = "An integration test to verify the response code from a put call") 58 | public void comparePutResponseCode200Test() { 59 | // use this object to verify the app looks as expected 60 | Call call = this.calls.get(); 61 | // perform some actions 62 | call.put("posts/3", new Request()).verifyEquals().code(200); 63 | // verify 1 issue 64 | finish(1); 65 | } 66 | 67 | @Test(groups = {"integration", "service", "httpdelete", "https"}, 68 | description = "An integration test to verify the response code from a delete call") 69 | public void compareDeleteResponseCode200Test() { 70 | // use this object to verify the app looks as expected 71 | Call call = this.calls.get(); 72 | // perform some actions 73 | call.delete("posts/5", new Request()).verifyEquals().code(200); 74 | // verify 1 issue 75 | finish(1); 76 | } 77 | } -------------------------------------------------------------------------------- /src/test/java/integration/ServicesOverrideIT.java: -------------------------------------------------------------------------------- 1 | package integration; 2 | 3 | import com.coveros.selenified.services.Call; 4 | import com.coveros.selenified.services.HTTP.ContentType; 5 | import com.coveros.selenified.services.Request; 6 | import com.google.gson.JsonObject; 7 | import org.testng.ITestContext; 8 | import org.testng.annotations.BeforeClass; 9 | import org.testng.annotations.Test; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | public class ServicesOverrideIT extends ServicesBase { 15 | 16 | @BeforeClass(alwaysRun = true) 17 | public void setupHeaders(ITestContext test) { 18 | // for this test, we want to change the default headers for each call 19 | Map headers = new HashMap<>(); 20 | headers.put("X-Atlassian-Token", "check"); 21 | addHeaders(this, test, headers); 22 | setContentType(this, test, ContentType.FORMDATA); 23 | // for this particular test, we want to set some bogus credentials 24 | setCredentials(this, test, "servicesUsername", "servicesPassword"); 25 | } 26 | 27 | @Test(groups = {"integration", "service", "headers"}, 28 | description = "An integration test to verify we can successfully set header values") 29 | public void addHeaderTest() { 30 | // use this object to verify the app looks as expected 31 | Call call = this.calls.get(); 32 | //set some custom headers 33 | Map headers = new HashMap<>(); 34 | headers.put("X-Atlassian-Token", "no-check"); 35 | call.addHeaders(headers); 36 | // perform some actions 37 | call.get("posts/", new Request()).verifyEquals().code(200); 38 | // verify no issues 39 | finish(); 40 | } 41 | 42 | @Test(groups = {"integration", "service", "headers"}, 43 | description = "An integration test to verify we can successfully set header values") 44 | public void addHeaderDataTest() { 45 | // use this object to verify the app looks as expected 46 | Call call = this.calls.get(); 47 | //set some custom headers 48 | Map headers = new HashMap<>(); 49 | headers.put("X-Atlassian-Token", "no-check"); 50 | call.addHeaders(headers); 51 | // perform some actions - this will fail as application/xml isn't supported 52 | call.post("posts/", new Request().setJsonPayload(new JsonObject())).verifyEquals().code(201); 53 | // verify one issue 54 | finish(1); 55 | } 56 | 57 | @Test(groups = {"integration", "service", "headers"}, 58 | description = "An integration test to verify we can successfully override standard header values") 59 | public void overrideAcceptTest() { 60 | // use this object to verify the app looks as expected 61 | Call call = this.calls.get(); 62 | //set some custom headers 63 | Map headers = new HashMap<>(); 64 | headers.put("Accept", "no-check"); 65 | call.resetHeaders(); 66 | call.addHeaders(headers); 67 | // perform some actions 68 | call.get("posts/").verifyEquals().code(200); 69 | // verify no issues 70 | finish(); 71 | } 72 | 73 | @Test(groups = {"integration", "service", "headers"}, 74 | description = "An integration test to verify we can successfully override standard header values") 75 | public void overrideCredentialsTest() { 76 | // use this object to verify the app looks as expected 77 | Call call = this.calls.get(); 78 | //set some custom credentials 79 | call.addCredentials("hello", "world"); 80 | // perform some actions 81 | call.get("posts/").verifyEquals().code(200); 82 | // verify no issues 83 | finish(); 84 | } 85 | } -------------------------------------------------------------------------------- /src/test/java/integration/ServicesResponseIT.java: -------------------------------------------------------------------------------- 1 | package integration; 2 | 3 | import com.coveros.selenified.services.Call; 4 | import com.coveros.selenified.services.Request; 5 | import org.testng.annotations.Test; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | import static org.testng.Assert.assertFalse; 11 | import static org.testng.Assert.assertTrue; 12 | 13 | public class ServicesResponseIT extends ServicesBase { 14 | 15 | @Test(groups = {"integration", "service", "httpget", "response"}, 16 | description = "An integration test to verify json array response for data check") 17 | public void verifyJsonArrayDataCheckGetCall() { 18 | // use this object to verify the app looks as expected 19 | Call call = this.calls.get(); 20 | // perform some actions 21 | assertTrue(call.get("posts/").isData()); 22 | // verify no issues 23 | finish(); 24 | } 25 | 26 | @Test(groups = {"integration", "service", "httpget", "response"}, 27 | description = "An integration test to verify json object response for data check") 28 | public void verifyJsonObjectDataCheckGetCall() { 29 | // use this object to verify the app looks as expected 30 | Call call = this.calls.get(); 31 | // perform some actions 32 | Map params = new HashMap<>(); 33 | params.put("id", 4); 34 | assertTrue(call.get("posts/", new Request().setUrlParams(params)).isData()); 35 | // verify no issues 36 | finish(); 37 | } 38 | 39 | @Test(groups = {"integration", "service", "httpget", "response"}, 40 | description = "An integration test to verify message response for data check") 41 | public void verifyMessageDataCheckGetCall() { 42 | // use this object to verify the app looks as expected 43 | Call call = this.calls.get(); 44 | // perform some actions 45 | assertFalse(call.get("null/").isData()); 46 | // verify no issues 47 | finish(); 48 | } 49 | } -------------------------------------------------------------------------------- /src/test/java/integration/ServicesResponseVerifyMatchesIT.java: -------------------------------------------------------------------------------- 1 | package integration; 2 | 3 | import com.coveros.selenified.services.Call; 4 | import com.coveros.selenified.services.Response; 5 | import com.google.gson.JsonArray; 6 | import org.testng.annotations.Test; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class ServicesResponseVerifyMatchesIT extends ServicesBase { 12 | 13 | //negative checks for verify equals 14 | 15 | @Test(groups = {"integration", "service", "httpget", "response"}, 16 | description = "An integration test to verify response code negative responses") 17 | public void negativeSuccessfulGetCall() { 18 | // use this object to verify the app looks as expected 19 | Call call = this.calls.get(); 20 | // perform some actions 21 | call.get("posts/").verifyMatches().code("301"); 22 | // verify 1 issue 23 | finish(1); 24 | } 25 | 26 | @Test(groups = {"integration", "service", "httpget", "response"}, 27 | description = "An integration test to verify response code negative responses") 28 | public void successfulGetCall() { 29 | // use this object to verify the app looks as expected 30 | Call call = this.calls.get(); 31 | // perform some actions 32 | call.get("posts/").verifyMatches().code("([02]+)"); 33 | // verify no issues 34 | finish(); 35 | } 36 | 37 | @Test(groups = {"integration", "service", "httpget", "response"}, 38 | description = "An integration test to verify json data response") 39 | public void verifyJsonCrumbsEmpty() { 40 | // use this object to verify the app looks as expected 41 | Call call = this.calls.get(); 42 | // perform some actions 43 | call.get("posts/?id=4").verifyMatches().nestedValue(new ArrayList<>(), "(.*)"); 44 | // verify no issues 45 | finish(); 46 | } 47 | 48 | @Test(groups = {"integration", "service", "httpget", "response"}, 49 | description = "An integration test to verify json data response") 50 | public void verifyJsonCrumbsSingle() { 51 | List crumbs = new ArrayList<>(); 52 | crumbs.add("userId"); 53 | // use this object to verify the app looks as expected 54 | Call call = this.calls.get(); 55 | // perform some actions 56 | call.get("posts/?id=4").verifyMatches().nestedValue(crumbs, "[\\d]"); 57 | // verify no issues 58 | finish(); 59 | } 60 | 61 | @Test(groups = {"integration", "service", "httpget", "response"}, 62 | description = "An integration test to verify json data response") 63 | public void verifyJsonCrumbsDouble() { 64 | List crumbs = new ArrayList<>(); 65 | crumbs.add("userId"); 66 | crumbs.add("user"); 67 | // use this object to verify the app looks as expected 68 | Call call = this.calls.get(); 69 | // perform some actions 70 | call.get("posts/?id=4").verifyMatches().nestedValue(crumbs, "[\\d]"); 71 | // verify no issues 72 | finish(1); 73 | } 74 | 75 | @Test(groups = {"integration", "service", "httpget", "response"}, 76 | description = "An integration test to verify json data response") 77 | public void verifyJsonCrumbsNoObject() { 78 | List crumbs = new ArrayList<>(); 79 | crumbs.add("userId"); 80 | // use this object to verify the app looks as expected 81 | Call call = this.calls.get(); 82 | // perform some actions 83 | call.get("posts/").verifyMatches().nestedValue(crumbs, "[\\d]"); 84 | // verify no issues 85 | finish(1); 86 | } 87 | 88 | @Test(groups = {"integration", "service", "httpget", "response"}, 89 | description = "An integration test to verify json data response") 90 | public void verifyJsonCrumbsBadCrumb() { 91 | List crumbs = new ArrayList<>(); 92 | crumbs.add("user"); 93 | // use this object to verify the app looks as expected 94 | Call call = this.calls.get(); 95 | // perform some actions 96 | call.get("posts/?id=4").verifyMatches().nestedValue(crumbs, "[\\d]"); 97 | // verify no issues 98 | finish(1); 99 | } 100 | 101 | @Test(groups = {"integration", "service", "httpget", "response"}, 102 | description = "An integration test to verify json data response") 103 | public void verifyJsonCrumbsMisMatch() { 104 | List crumbs = new ArrayList<>(); 105 | crumbs.add("userId"); 106 | // use this object to verify the app looks as expected 107 | Call call = this.calls.get(); 108 | // perform some actions 109 | call.get("posts/?id=4").verifyMatches().nestedValue(crumbs, "hi"); 110 | // verify no issues 111 | finish(1); 112 | } 113 | 114 | @Test(groups = {"integration", "service", "httpget", "response"}, 115 | description = "An integration test to verify json data response") 116 | public void verifyJsonArrayMessageMismatch() { 117 | JsonArray json = new JsonArray(); 118 | json.add(json1); 119 | json.add(json2); 120 | json.add(json3); 121 | // use this object to verify the app looks as expected 122 | Call call = this.calls.get(); 123 | // perform some actions 124 | call.get("posts/").verifyMatches().message(json.toString()); 125 | // verify 1 issue 126 | finish(1); 127 | } 128 | 129 | @Test(groups = {"integration", "service", "httpget", "response"}, 130 | description = "An integration test to verify json data response") 131 | public void verifyJsonObjectMessageMismatch() { 132 | JsonArray json = new JsonArray(); 133 | json.add(json4); 134 | // use this object to verify the app looks as expected 135 | Call call = this.calls.get(); 136 | // perform some actions 137 | call.get("posts/?id=4").verifyMatches().message(json.toString()); 138 | // verify 1 issue 139 | finish(1); 140 | } 141 | 142 | @Test(groups = {"integration", "service", "httpget", "response"}, 143 | description = "An integration test to verify json data response") 144 | public void verifyJsonMessageMessageMismatch() { 145 | // use this object to verify the app looks as expected 146 | Call call = this.calls.get(); 147 | // perform some actions 148 | Response response = call.get("posts/?id=4"); 149 | response.verifyMatches().message("Something"); 150 | // verify 1 issue 151 | finish(1); 152 | } 153 | 154 | @Test(groups = {"integration", "service", "httpget", "response"}, 155 | description = "An integration test to verify json data response") 156 | public void verifyJsonMessageMessageNull() { 157 | // use this object to verify the app looks as expected 158 | Call call = this.calls.get(); 159 | // perform some actions 160 | Response response = call.get("/null/"); 161 | response.verifyMatches().message("Something"); 162 | // verify 1 issue 163 | finish(1); 164 | } 165 | } -------------------------------------------------------------------------------- /src/test/java/integration/WebBase.java: -------------------------------------------------------------------------------- 1 | package integration; 2 | 3 | import com.coveros.selenified.Selenified; 4 | import org.mockserver.integration.ClientAndServer; 5 | import org.testng.ITestContext; 6 | import org.testng.annotations.AfterSuite; 7 | import org.testng.annotations.BeforeClass; 8 | import org.testng.annotations.BeforeSuite; 9 | 10 | import java.io.IOException; 11 | import java.nio.file.Files; 12 | import java.nio.file.Paths; 13 | 14 | import static org.mockserver.integration.ClientAndServer.startClientAndServer; 15 | import static org.mockserver.model.HttpRequest.request; 16 | import static org.mockserver.model.HttpResponse.response; 17 | 18 | public class WebBase extends Selenified { 19 | private ClientAndServer mockServer; 20 | private int mockPort = 1070; 21 | 22 | 23 | @BeforeClass(alwaysRun = true) 24 | public void beforeClass(ITestContext test) { 25 | // set the base URL for the tests here 26 | setAppURL(this, test, "http://localhost:" + mockPort + "/"); 27 | // set the author of the tests here 28 | setAuthor(this, test, "Max Saperstone\n
max.saperstone@coveros.com"); 29 | // set the version of the tests or of the software, possibly with a dynamic check 30 | setVersion(this, test, "3.3.1"); 31 | 32 | // when running on sauce labs, timezones can mess with the cookie expiration date, so setting it here to EST 33 | addAdditionalDesiredCapabilities(this, test, "timeZone", "New_York"); 34 | } 35 | 36 | private static String readFile(String path) throws IOException { 37 | byte[] encoded = Files.readAllBytes(Paths.get(path)); 38 | return new String(encoded); 39 | } 40 | 41 | @BeforeSuite(alwaysRun = true) 42 | public void startMockServer() throws IOException { 43 | if( System.getProperty("mockPort") != null) { 44 | mockPort += Integer.valueOf(System.getProperty("mockPort")); 45 | } 46 | System.setProperty("mockserver.logLevel", "OFF"); 47 | mockServer = startClientAndServer(mockPort); 48 | mockServer.when(request().withMethod("GET").withPath("/")) 49 | .respond(response().withBody(readFile("public/index.html"))); 50 | mockServer.when(request().withMethod("GET").withPath("/next_page.html")) 51 | .respond(response().withBody(readFile("public/next_page.html"))); 52 | } 53 | 54 | @AfterSuite(alwaysRun = true) 55 | public void stopMockServer() { 56 | mockServer.stop(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/integration/hub/LambdaTestIT.java: -------------------------------------------------------------------------------- 1 | package integration.hub; 2 | 3 | import com.coveros.selenified.Selenified; 4 | import com.coveros.selenified.application.App; 5 | import com.coveros.selenified.services.Call; 6 | import com.coveros.selenified.services.Response; 7 | import com.coveros.selenified.utilities.Hub; 8 | import org.openqa.selenium.remote.RemoteWebDriver; 9 | import org.openqa.selenium.remote.SessionId; 10 | import org.testng.ITestContext; 11 | import org.testng.annotations.BeforeClass; 12 | import org.testng.annotations.DataProvider; 13 | import org.testng.annotations.Test; 14 | 15 | import java.io.IOException; 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | public class LambdaTestIT extends Selenified { 20 | 21 | private ITestContext test; 22 | 23 | @BeforeClass(alwaysRun = true) 24 | public void beforeClass(ITestContext test) { 25 | // set the base URL for the tests here 26 | setAppURL(this, test, "https://api.lambdatest.com/automation/api/v1/"); 27 | // set the author of the tests here 28 | setAuthor(this, test, "Max Saperstone\n
max.saperstone@coveros.com"); 29 | // set the version of the tests or of the software, possibly with a dynamic check 30 | setVersion(this, test, "3.3.1"); 31 | 32 | this.test = test; 33 | } 34 | 35 | @Test(groups = {"integration", "hub", "lambda"}, description = "An integration test to check that lambda gets all expected information") 36 | public void hubTitleTest() { 37 | // use this object to manipulate the app 38 | App app = this.apps.get(); 39 | // verify the correct page title 40 | app.azzert().urlEquals("https://api.lambdatest.com/automation/api/v1/"); 41 | // capture the session_id 42 | test.setAttribute("HUB_SESSION_ID", ((RemoteWebDriver) app.getDriver()).getSessionId()); 43 | test.setAttribute("HUB_BUILD", app.getDesiredCapabilities().getCapability("build")); 44 | // verify no issues 45 | finish(); 46 | } 47 | 48 | @DataProvider(name = "search terms", parallel = true) 49 | public Object[][] DataSetOptions2() { 50 | return new Object[][]{new Object[]{"hi"}}; 51 | } 52 | 53 | @Test(dataProvider = "search terms", groups = {"integration", "hub", "lambda"}, 54 | description = "An integration test to check that lambda gets all expected information") 55 | public void hubSearchTest(String message) { 56 | // use this object to manipulate the app 57 | App app = this.apps.get(); 58 | // find the search box element and create the object 59 | app.azzert().textPresent(message); 60 | // capture the session_id 61 | test.setAttribute("PARAM_SESSION_ID", ((RemoteWebDriver) app.getDriver()).getSessionId()); 62 | // verify no issues 63 | finish(); 64 | } 65 | 66 | @Test(groups = {"integration", "hub", "lambda", "lambdaAPI"}, dependsOnMethods = {"hubTitleTest"}, 67 | description = "An integration test to check that lambda get all expected information") 68 | public void lambdaPassedTest(ITestContext iTestContext) throws IOException { 69 | SessionId sessionId = (SessionId) iTestContext.getAttribute("HUB_SESSION_ID"); 70 | Hub hub = new Hub(); 71 | Call call = this.calls.get(); 72 | call.addCredentials(hub.getUsername(), hub.getPassword()); 73 | Response response = call.get("sessions/" + sessionId.toString()); 74 | List jsonDataSets = new ArrayList<>(); 75 | jsonDataSets.add("data"); 76 | jsonDataSets.add("status_ind"); 77 | response.assertEquals().nestedValue(jsonDataSets, "passed"); 78 | finish(); 79 | } 80 | 81 | @Test(groups = {"integration", "hub", "lambda", "lambdaAPI"}, dependsOnMethods = {"hubTitleTest"}, 82 | description = "An integration test to check that lambda get all expected information") 83 | public void lambdaBuildTest(ITestContext iTestContext) throws IOException { 84 | SessionId sessionId = (SessionId) iTestContext.getAttribute("HUB_SESSION_ID"); 85 | String buildName = iTestContext.getAttribute("HUB_BUILD").toString(); 86 | Hub hub = new Hub(); 87 | Call call = this.calls.get(); 88 | call.addCredentials(hub.getUsername(), hub.getPassword()); 89 | Response response = call.get("sessions/" + sessionId.toString()); 90 | List jsonDataSets = new ArrayList<>(); 91 | jsonDataSets.add("data"); 92 | jsonDataSets.add("build_name"); 93 | response.assertEquals().nestedValue(jsonDataSets, buildName); 94 | finish(); 95 | } 96 | 97 | @Test(groups = {"integration", "hub", "lambda", "lambdaAPI"}, dependsOnMethods = {"hubTitleTest"}, 98 | description = "An integration test to check that lambda get all expected information") 99 | public void lambdaNameTest(ITestContext iTestContext) throws IOException { 100 | SessionId sessionId = (SessionId) iTestContext.getAttribute("HUB_SESSION_ID"); 101 | Hub hub = new Hub(); 102 | Call call = this.calls.get(); 103 | call.addCredentials(hub.getUsername(), hub.getPassword()); 104 | Response response = call.get("sessions/" + sessionId.toString()); 105 | List jsonDataSets = new ArrayList<>(); 106 | jsonDataSets.add("data"); 107 | jsonDataSets.add("name"); 108 | response.assertEquals().nestedValue(jsonDataSets, "integration.hub.LambdaTestIT.hubTitleTest"); 109 | finish(); 110 | } 111 | 112 | @Test(groups = {"integration", "hub", "lambda", "lambdaAPI"}, dependsOnMethods = {"hubSearchTest"}, 113 | description = "An integration test to check that lambda get all expected information") 114 | public void lambdaComplexNameTest(ITestContext iTestContext) throws IOException { 115 | SessionId paramSessionId = (SessionId) iTestContext.getAttribute("PARAM_SESSION_ID"); 116 | Hub hub = new Hub(); 117 | Call call = this.calls.get(); 118 | call.addCredentials(hub.getUsername(), hub.getPassword()); 119 | Response response = call.get("sessions/" + paramSessionId.toString()); 120 | List jsonDataSets = new ArrayList<>(); 121 | jsonDataSets.add("data"); 122 | jsonDataSets.add("name"); 123 | response.assertEquals().nestedValue(jsonDataSets, "integration.hub.LambdaTestIT.hubSearchTestWithOptionHi"); 124 | finish(); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/test/java/sample/MainPage.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import com.coveros.selenified.Locator; 4 | import com.coveros.selenified.application.App; 5 | import com.coveros.selenified.element.Element; 6 | 7 | final class MainPage { 8 | 9 | // our page elements 10 | private final Element click; 11 | private final Element alert; 12 | private final Element carList; 13 | public final Element checkbox; 14 | 15 | public MainPage(App app) { 16 | click = app.newElement(Locator.CLASSNAME, "click"); 17 | alert = app.newElement(Locator.CSS, "input#alert_button"); 18 | carList = app.newElement(Locator.ID, "car_list"); 19 | checkbox = app.newElement(Locator.XPATH, "//form/input[@type='checkbox']"); 20 | } 21 | 22 | public void selectCar(String car) { 23 | carList.selectOption(car); 24 | } 25 | 26 | public void assertCar(String car) { 27 | carList.assertEquals().selectedOption(car); 28 | } 29 | 30 | public void generateAlert() { 31 | click.click(); 32 | alert.click(); 33 | } 34 | } -------------------------------------------------------------------------------- /src/test/java/sample/POMSampleIT.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import com.coveros.selenified.application.App; 4 | import integration.WebBase; 5 | import org.testng.annotations.BeforeMethod; 6 | import org.testng.annotations.DataProvider; 7 | import org.testng.annotations.Test; 8 | 9 | public class POMSampleIT extends WebBase { 10 | 11 | @DataProvider(name = "car list items", parallel = true) 12 | public Object[][] DataSetOptions() { 13 | return new Object[][]{new Object[]{"Volvo"}, new Object[]{"Saab"}, new Object[]{"Mercedes"}}; 14 | } 15 | 16 | private final ThreadLocal main = new ThreadLocal<>(); 17 | 18 | @BeforeMethod(alwaysRun = true) 19 | public void setupApp() { 20 | main.set(new MainPage(this.apps.get())); 21 | } 22 | 23 | @Test(dataProvider = "car list items", groups = {"sample", "pom"}, 24 | description = "A sample test using a data provider to perform searches") 25 | public void sampleTestWDataProvider(String listItem) { 26 | // our test actions - use our threadsafe main object 27 | main.get().selectCar(listItem); 28 | main.get().assertCar(listItem); 29 | // close out the test 30 | finish(); 31 | } 32 | 33 | // skipping safari as it doesn't support modal dialogs: https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/3862 34 | @Test(groups = {"sample", "pom", "alert", "no-safari"}, description = "A sample test using a data provider to perform searches") 35 | public void sampleTest() { 36 | // grab our main app object 37 | App app = this.apps.get(); 38 | // grab our main threadsafe object for future use 39 | MainPage main = this.main.get(); 40 | // our test actions 41 | main.generateAlert(); 42 | app.azzert().alertPresent(); 43 | app.acceptAlert(); 44 | app.azzert().alertNotPresent(); 45 | } 46 | 47 | @Test(groups = {"sample", "pom"}, description = "A sample test using a data provider to perform searches") 48 | public void sampleTestWMatches() { 49 | // define a new main object 50 | MainPage main = new MainPage(this.apps.get()); 51 | // perform some actions 52 | for (int match = 0; match < main.checkbox.get().matchCount(); match++) { 53 | main.checkbox.setMatch(match); 54 | main.checkbox.click(); 55 | main.checkbox.assertState().checked(); 56 | } 57 | // close out the test 58 | finish(); 59 | } 60 | } -------------------------------------------------------------------------------- /src/test/java/sample/ReadmeSampleIT.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import com.coveros.selenified.Locator; 4 | import com.coveros.selenified.Selenified; 5 | import com.coveros.selenified.application.App; 6 | import com.coveros.selenified.element.Element; 7 | import com.coveros.selenified.services.Call; 8 | import com.coveros.selenified.services.Request; 9 | import org.testng.ITestContext; 10 | import org.testng.annotations.BeforeClass; 11 | import org.testng.annotations.DataProvider; 12 | import org.testng.annotations.Test; 13 | 14 | import java.util.HashMap; 15 | 16 | public class ReadmeSampleIT extends Selenified { 17 | 18 | @BeforeClass(alwaysRun = true) 19 | public void beforeClass(ITestContext test) { 20 | // set the base URL for the tests here 21 | setAppURL(this, test, "https://www.coveros.com/"); 22 | } 23 | 24 | @DataProvider(name = "coveros search terms", parallel = true) 25 | public Object[][] DataSetOptions() { 26 | return new Object[][]{new Object[]{"python"}, 27 | new Object[]{"perl"}, new Object[]{"bash"},}; 28 | } 29 | 30 | @Test(groups = {"sample", "coveros"}, description = "A sample selenium test to check a title") 31 | public void sampleTest() { 32 | // use this object to manipulate the app 33 | App app = this.apps.get(); 34 | // verify the correct page title 35 | app.azzert().titleEquals("Coveros | Bringing together agile and security to deliver superior software"); 36 | // verify no issues 37 | finish(); 38 | } 39 | 40 | @Test(dataProvider = "coveros search terms", groups = {"sample", "coveros"}, 41 | description = "A sample selenium test using a data provider to perform a search") 42 | public void sampleTestWDataProvider(String searchTerm) { 43 | // use this object to manipulate the app 44 | App app = this.apps.get(); 45 | // find the search box element and create the object 46 | Element searchBox = app.newElement(Locator.NAME, "s"); 47 | //perform the search and submit 48 | searchBox.type(searchTerm); 49 | searchBox.submit(); 50 | //wait for the page to return the results 51 | app.newElement(Locator.ID, "recent-posts-4").waitForState().present(); 52 | // verify the correct page title 53 | app.azzert().titleEquals("You searched for " + searchTerm + " - Coveros"); 54 | // verify no issues 55 | finish(); 56 | } 57 | 58 | @Test(groups = {"sample", "service", "coveros", "https"}, description = "A sample web services test to verify the response code") 59 | public void sampleServicesSearchTest() { 60 | HashMap params = new HashMap<>(); 61 | params.put("s", "Max+Saperstone"); 62 | // use this object to verify the app looks as expected 63 | Call call = this.calls.get(); 64 | // retrieve the zip code and verify the return code 65 | call.get("", new Request().setUrlParams(params)).assertEquals().code(403); 66 | // verify no issues 67 | finish(); 68 | } 69 | } -------------------------------------------------------------------------------- /src/test/java/sample/SimpleSampleIT.java: -------------------------------------------------------------------------------- 1 | package sample; 2 | 3 | import com.coveros.selenified.Locator; 4 | import com.coveros.selenified.application.App; 5 | import com.coveros.selenified.element.Element; 6 | import integration.WebBase; 7 | import org.testng.annotations.DataProvider; 8 | import org.testng.annotations.Test; 9 | 10 | public class SimpleSampleIT extends WebBase { 11 | 12 | @DataProvider(name = "car list items", parallel = true) 13 | public Object[][] DataSetOptions() { 14 | return new Object[][]{new Object[]{"Volvo"}, new Object[]{"Saab"}, new Object[]{"Mercedes"}}; 15 | } 16 | 17 | @Test(groups = {"sample"}, description = "A sample test to check a title") 18 | public void sampleTest() { 19 | // use this object to manipulate the app 20 | App app = this.apps.get(); 21 | // perform the verification 22 | app.azzert().titleEquals("Selenified Test Page"); 23 | } 24 | 25 | @Test(dataProvider = "car list items", groups = {"sample"}, 26 | description = "A sample test using a data provider to perform searches") 27 | public void sampleTestWDataProvider(String listItem) { 28 | // use this object to manipulate the app 29 | App app = this.apps.get(); 30 | // perform some actions 31 | app.newElement(Locator.ID, "car_list").selectOption(listItem); 32 | // close out the test 33 | finish(); 34 | } 35 | 36 | @Test(groups = {"sample"}, description = "A sample test to show how to loop through elements with multiple matches") 37 | public void sampleTestLoopThroughElements() { 38 | // use this object to manipulate the app 39 | App app = this.apps.get(); 40 | // perform some actions 41 | Element element = app.newElement(Locator.XPATH, "//form/input[@type='checkbox']"); 42 | for (int match = 0; match < element.get().matchCount(); match++) { 43 | element.setMatch(match); 44 | element.click(); 45 | element.assertState().checked(); 46 | } 47 | // close out the test 48 | finish(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/unit/AppTest.java: -------------------------------------------------------------------------------- 1 | package unit; 2 | 3 | import com.coveros.selenified.Browser; 4 | import com.coveros.selenified.Capabilities; 5 | import com.coveros.selenified.application.App; 6 | import com.coveros.selenified.exceptions.InvalidBrowserException; 7 | import com.coveros.selenified.exceptions.InvalidHubException; 8 | import com.coveros.selenified.exceptions.InvalidProxyException; 9 | import org.openqa.selenium.WebDriverException; 10 | import org.testng.annotations.Test; 11 | 12 | import java.net.MalformedURLException; 13 | 14 | import static com.coveros.selenified.utilities.Property.HUB; 15 | import static org.testng.Assert.fail; 16 | 17 | public class AppTest extends SaveProperties { 18 | 19 | @Test(expectedExceptions = WebDriverException.class) 20 | public void checkElementTypeTest() throws InvalidBrowserException, MalformedURLException, InvalidProxyException, InvalidHubException { 21 | System.setProperty(HUB, "http://myurl"); 22 | new App(new Capabilities(new Browser("htmlunIT")), null); 23 | } 24 | 25 | @Test(expectedExceptions = MalformedURLException.class) 26 | public void checkElementTypeBadURLTest() throws InvalidBrowserException, MalformedURLException, InvalidProxyException, InvalidHubException { 27 | System.setProperty(HUB, "myurl"); 28 | new App(new Capabilities(new Browser("htmlunit")), null); 29 | } 30 | 31 | @Test(expectedExceptions = InvalidBrowserException.class) 32 | public void nullCapabilitiesTest() throws InvalidBrowserException, MalformedURLException, InvalidProxyException, InvalidHubException { 33 | new App(null, null); 34 | fail("Expected an InvalidBrowserException"); 35 | } 36 | } -------------------------------------------------------------------------------- /src/test/java/unit/CallTest.java: -------------------------------------------------------------------------------- 1 | package unit; 2 | 3 | import com.coveros.selenified.exceptions.InvalidBrowserException; 4 | import com.coveros.selenified.exceptions.InvalidHTTPException; 5 | import com.coveros.selenified.exceptions.InvalidProxyException; 6 | import com.coveros.selenified.exceptions.InvalidReporterException; 7 | import com.coveros.selenified.services.Call; 8 | import com.coveros.selenified.services.HTTP; 9 | import com.coveros.selenified.utilities.Reporter; 10 | import org.testng.annotations.AfterMethod; 11 | import org.testng.annotations.Test; 12 | 13 | import java.io.File; 14 | import java.util.HashMap; 15 | 16 | public class CallTest { 17 | 18 | private Reporter reporter = new Reporter(null, null, null, null, null, null, null, null, null); 19 | private HTTP http = new HTTP(reporter, "SomeURL"); 20 | 21 | public CallTest() throws InvalidBrowserException, InvalidProxyException { 22 | } 23 | 24 | @AfterMethod 25 | public void cleanup() { 26 | new File("null.html").delete(); 27 | } 28 | 29 | @Test(expectedExceptions = InvalidHTTPException.class) 30 | public void constructorNullTest() throws InvalidHTTPException, InvalidReporterException { 31 | // just verify no errors are thrown 32 | new Call(null, null); 33 | } 34 | 35 | @Test 36 | public void constructorHttpTest() throws InvalidHTTPException, InvalidReporterException { 37 | // just verify no errors are thrown 38 | new Call(http, null); 39 | } 40 | 41 | @Test(expectedExceptions = InvalidReporterException.class) 42 | public void constructorNullReporterTest() throws InvalidHTTPException, InvalidReporterException { 43 | // just verify no errors are thrown 44 | new Call(new HTTP(null, "SomeURL"), null); 45 | } 46 | 47 | @Test 48 | public void constructorTest() throws InvalidHTTPException, InvalidReporterException { 49 | new Call(http, new HashMap<>()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/unit/ExceptionTest.java: -------------------------------------------------------------------------------- 1 | package unit; 2 | 3 | import com.coveros.selenified.Browser; 4 | import com.coveros.selenified.Capabilities; 5 | import com.coveros.selenified.exceptions.InvalidBrowserException; 6 | import com.coveros.selenified.exceptions.InvalidHubException; 7 | import com.coveros.selenified.exceptions.InvalidProxyException; 8 | import org.testng.annotations.Test; 9 | 10 | import static org.testng.Assert.fail; 11 | 12 | public class ExceptionTest { 13 | 14 | @Test(expectedExceptions = InvalidBrowserException.class) 15 | public void invalidBrowserExceptionTest() throws InvalidBrowserException, InvalidProxyException, InvalidHubException { 16 | new Capabilities(new Browser("Android")); 17 | fail("Expected an InvalidBrowserException"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/unit/HTTPTest.java: -------------------------------------------------------------------------------- 1 | package unit; 2 | 3 | import com.coveros.selenified.services.HTTP; 4 | import com.coveros.selenified.services.Request; 5 | import org.testng.annotations.Test; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | import static org.testng.Assert.*; 11 | 12 | public class HTTPTest { 13 | 14 | @Test 15 | public void useCredentialsEmptyTest() { 16 | HTTP http = new HTTP(null, "Service"); 17 | assertFalse(http.useCredentials()); 18 | } 19 | 20 | @Test 21 | public void useCredentialsBothTest() { 22 | HTTP http = new HTTP(null, "Service", "User", "Pass"); 23 | assertTrue(http.useCredentials()); 24 | } 25 | 26 | @Test 27 | public void useCredentialsNeitherTest() { 28 | HTTP http = new HTTP(null, "Service", "", ""); 29 | assertFalse(http.useCredentials()); 30 | } 31 | 32 | @Test 33 | public void useCredentialsUserTest() { 34 | HTTP http = new HTTP(null, "Service", "User", ""); 35 | assertFalse(http.useCredentials()); 36 | } 37 | 38 | @Test 39 | public void useCredentialsPassTest() { 40 | HTTP http = new HTTP(null, "Service", "", "Pass"); 41 | assertFalse(http.useCredentials()); 42 | } 43 | 44 | @Test 45 | public void buildStringNullParamTest() { 46 | HTTP http = new HTTP(null, "Service"); 47 | assertEquals(http.getRequestParams(null), ""); 48 | } 49 | 50 | @Test 51 | public void buildStringEmptyParamTest() { 52 | HTTP http = new HTTP(null, "Service"); 53 | assertEquals(http.getRequestParams(new Request()), ""); 54 | } 55 | 56 | @Test 57 | public void buildStringNoParamTest() { 58 | HTTP http = new HTTP(null, "Service"); 59 | assertEquals(http.getRequestParams(new Request().setUrlParams(new HashMap<>())), ""); 60 | } 61 | 62 | @Test 63 | public void buildStringSingleParamTest() { 64 | HTTP http = new HTTP(null, "Service"); 65 | Map params = new HashMap<>(); 66 | params.put("hello", "world"); 67 | assertEquals(http.getRequestParams(new Request().setUrlParams(params)), "?hello=world"); 68 | } 69 | 70 | @Test 71 | public void buildStringMultipleParamsTest() { 72 | HTTP http = new HTTP(null, "Service"); 73 | Map params = new HashMap<>(); 74 | params.put("hello", "world"); 75 | params.put("john", 5); 76 | assertEquals(http.getRequestParams(new Request().setUrlParams(params)), "?john=5&hello=world"); 77 | } 78 | 79 | @Test 80 | public void checkAddingCredentialsTest() { 81 | HTTP http = new HTTP(null, "Service"); 82 | http.addCredentials("User", "Pass"); 83 | assertTrue(http.useCredentials()); 84 | } 85 | 86 | @Test 87 | public void checkAddingUserCredentialsTest() { 88 | HTTP http = new HTTP(null, "Service"); 89 | http.addCredentials("User", ""); 90 | assertFalse(http.useCredentials()); 91 | } 92 | 93 | @Test 94 | public void checkAddingPassCredentialsTest() { 95 | HTTP http = new HTTP(null, "Service"); 96 | http.addCredentials("", "Pass"); 97 | assertFalse(http.useCredentials()); 98 | } 99 | 100 | @Test 101 | public void checkAddingNoCredentialsTest() { 102 | HTTP http = new HTTP(null, "Service"); 103 | http.addCredentials("", ""); 104 | assertFalse(http.useCredentials()); 105 | } 106 | 107 | @Test 108 | public void checkAddingBaseUrl() { 109 | HTTP http = new HTTP(null, "Service"); 110 | assertEquals(http.getServiceBaseUrl(), "Service"); 111 | } 112 | 113 | @Test 114 | public void checkAddingNullBaseUrl() { 115 | HTTP http = new HTTP(null, null); 116 | assertNull(http.getServiceBaseUrl()); 117 | } 118 | 119 | @Test 120 | public void checkAddingEmptyBaseUrl() { 121 | HTTP http = new HTTP(null, ""); 122 | assertEquals(http.getServiceBaseUrl(), ""); 123 | } 124 | 125 | @Test 126 | public void getHeadersDefaultTest() { 127 | HTTP http = new HTTP(null, ""); 128 | Map map = new HashMap<>(); 129 | map.put("Accept", "application/json"); 130 | map.put("Content-length", "0"); 131 | map.put("Content-Type", "application/json; charset=UTF-8"); 132 | assertEquals(http.getHeaders(), map); 133 | } 134 | 135 | @Test 136 | public void getHeadersExtraTest() { 137 | HTTP http = new HTTP(null, ""); 138 | Map map = new HashMap<>(); 139 | map.put("Accept", "application/json"); 140 | map.put("Content-length", "0"); 141 | map.put("Content-Type", "application/json; charset=UTF-8"); 142 | map.put("Age", 1234); 143 | Map headers = new HashMap<>(); 144 | headers.put("Age", 1234); 145 | http.addHeaders(headers); 146 | assertEquals(http.getHeaders(), map); 147 | } 148 | 149 | @Test 150 | public void getHeadersOverrideTest() { 151 | HTTP http = new HTTP(null, ""); 152 | Map map = new HashMap<>(); 153 | map.put("Accept", "application/xml"); 154 | map.put("Content-length", "0"); 155 | map.put("Content-Type", "application/json; charset=UTF-8"); 156 | Map headers = new HashMap<>(); 157 | headers.put("Accept", "application/xml"); 158 | http.addHeaders(headers); 159 | assertEquals(http.getHeaders(), map); 160 | } 161 | 162 | @Test 163 | public void addHeadersDefaultTest() { 164 | HTTP http = new HTTP(null, ""); 165 | Map map = new HashMap<>(); 166 | map.put("Accept", "application/json"); 167 | map.put("Content-length", "0"); 168 | map.put("Content-Type", "application/json; charset=UTF-8"); 169 | http.addHeaders(new HashMap<>()); 170 | assertEquals(http.getHeaders(), map); 171 | } 172 | 173 | @Test 174 | public void addHeadersResetTest() { 175 | HTTP http = new HTTP(null, ""); 176 | Map map = new HashMap<>(); 177 | map.put("Accept", "application/json"); 178 | map.put("Content-length", "0"); 179 | map.put("Content-Type", "application/json; charset=UTF-8"); 180 | Map headers = new HashMap<>(); 181 | headers.put("Accept", "application/xml"); 182 | http.addHeaders(headers); 183 | http.resetHeaders(); 184 | assertEquals(http.getHeaders(), map); 185 | } 186 | } -------------------------------------------------------------------------------- /src/test/java/unit/HubTest.java: -------------------------------------------------------------------------------- 1 | package unit; 2 | 3 | import com.coveros.selenified.exceptions.InvalidHubException; 4 | import com.coveros.selenified.utilities.Hub; 5 | import org.testng.annotations.Test; 6 | 7 | import java.io.IOException; 8 | import java.net.MalformedURLException; 9 | import java.net.URL; 10 | 11 | import static com.coveros.selenified.utilities.Property.HUB; 12 | import static org.testng.Assert.*; 13 | import static org.testng.AssertJUnit.assertNull; 14 | 15 | public class HubTest extends SaveProperties { 16 | 17 | @Test 18 | public void defaultIsHubTest() { 19 | assertFalse(Hub.isHubSet()); 20 | } 21 | 22 | @Test 23 | public void defaultIsHubSystemEmptyTest() { 24 | System.setProperty(HUB, ""); 25 | assertFalse(Hub.isHubSet()); 26 | } 27 | 28 | @Test 29 | public void defaultIsHubSystemTest() { 30 | System.setProperty(HUB, "somehub"); 31 | assertTrue(Hub.isHubSet()); 32 | } 33 | 34 | @Test 35 | public void defaultIsHubFileEmptyTest() throws IOException { 36 | createPropertiesFile(""); 37 | assertFalse(Hub.isHubSet()); 38 | } 39 | 40 | @Test 41 | public void defaultIsHubFilePartialTest() throws IOException { 42 | createPropertiesFile(HUB); 43 | assertFalse(Hub.isHubSet()); 44 | } 45 | 46 | @Test 47 | public void defaultIsHubFileUnsetTest() throws IOException { 48 | createPropertiesFile(HUB + "="); 49 | assertFalse(Hub.isHubSet()); 50 | } 51 | 52 | @Test 53 | public void defaultIsHubFileTrueTest() throws IOException { 54 | createPropertiesFile(HUB + "=somehub"); 55 | assertTrue(Hub.isHubSet()); 56 | } 57 | 58 | @Test 59 | public void defaultIsHubOverrideEmptyTest() throws IOException { 60 | System.setProperty(HUB, ""); 61 | createPropertiesFile(HUB + "=somehub"); 62 | assertFalse(Hub.isHubSet()); 63 | } 64 | 65 | @Test 66 | public void defaultIsHubOverrideTrueTest() throws IOException { 67 | System.setProperty(HUB, "somehub"); 68 | createPropertiesFile(HUB + "="); 69 | assertTrue(Hub.isHubSet()); 70 | } 71 | 72 | @Test(expectedExceptions = InvalidHubException.class) 73 | public void defaultGetHubTest() throws MalformedURLException { 74 | new Hub().getHubURL(); 75 | } 76 | 77 | @Test(expectedExceptions = InvalidHubException.class) 78 | public void defaultGetHubSystemEmptyTest() throws MalformedURLException { 79 | System.setProperty(HUB, ""); 80 | new Hub().getHubURL(); 81 | } 82 | 83 | @Test(expectedExceptions = InvalidHubException.class) 84 | public void defaultGetHubSystemBadTest() throws MalformedURLException { 85 | System.setProperty(HUB, "somehub"); 86 | new Hub().getHubURL(); 87 | } 88 | 89 | @Test 90 | public void defaultGetHubSystemTest() throws MalformedURLException { 91 | System.setProperty(HUB, "https://somehub"); 92 | assertEquals(new Hub().getHubURL(), new URL("https://somehub/wd/hub")); 93 | } 94 | 95 | @Test(expectedExceptions = InvalidHubException.class) 96 | public void defaultGetHubFileEmptyTest() throws IOException { 97 | createPropertiesFile(""); 98 | new Hub().getHubURL(); 99 | } 100 | 101 | @Test(expectedExceptions = InvalidHubException.class) 102 | public void defaultGetHubFilePartialTest() throws IOException { 103 | createPropertiesFile(HUB); 104 | new Hub().getHubURL(); 105 | } 106 | 107 | @Test(expectedExceptions = InvalidHubException.class) 108 | public void defaultGetHubFileUnsetTest() throws IOException { 109 | createPropertiesFile(HUB + "="); 110 | new Hub().getHubURL(); 111 | } 112 | 113 | @Test(expectedExceptions = InvalidHubException.class) 114 | public void defaultGetHubFileBadTest() throws IOException { 115 | createPropertiesFile(HUB + "=somehub"); 116 | new Hub().getHubURL(); 117 | } 118 | 119 | 120 | @Test 121 | public void defaultGetHubFileTrueTest() throws IOException { 122 | createPropertiesFile(HUB + "=https://somehub"); 123 | assertEquals(new Hub().getHubURL(), new URL("https://somehub/wd/hub")); 124 | } 125 | 126 | @Test(expectedExceptions = InvalidHubException.class) 127 | public void defaultGetHubOverrideEmptyTest() throws IOException { 128 | System.setProperty(HUB, ""); 129 | createPropertiesFile(HUB + "=somehub"); 130 | new Hub().getHubURL(); 131 | } 132 | 133 | @Test(expectedExceptions = InvalidHubException.class) 134 | public void defaultGetHubOverrideBadTest() throws IOException { 135 | System.setProperty(HUB, "somehub"); 136 | createPropertiesFile(HUB + "="); 137 | new Hub().getHubURL(); 138 | } 139 | 140 | @Test 141 | public void defaultGetHubOverrideTrueTest() throws IOException { 142 | System.setProperty(HUB, "http://somehub"); 143 | createPropertiesFile(HUB + "="); 144 | assertEquals(new Hub().getHubURL(), new URL("http://somehub/wd/hub")); 145 | } 146 | 147 | @Test(expectedExceptions = InvalidHubException.class) 148 | public void getUserNoHubTest() throws MalformedURLException { 149 | new Hub().getUsername(); 150 | } 151 | 152 | @Test 153 | public void getUserNoUserTest() throws MalformedURLException { 154 | System.setProperty(HUB, "https://ondemand.saucelabs.com:443"); 155 | assertEquals(new Hub().getHubURL(), new URL("https://ondemand.saucelabs.com:443/wd/hub")); 156 | assertNull(new Hub().getUsername()); 157 | assertNull(new Hub().getPassword()); 158 | } 159 | 160 | @Test(expectedExceptions = InvalidHubException.class) 161 | public void getUserOnlyUserTest() throws MalformedURLException { 162 | System.setProperty(HUB, "https://sauceusername@ondemand.saucelabs.com:443"); 163 | new Hub().getUsername(); 164 | } 165 | 166 | @Test(expectedExceptions = InvalidHubException.class) 167 | public void getKeyNoHubTest() throws MalformedURLException { 168 | new Hub().getPassword(); 169 | } 170 | 171 | @Test 172 | public void getKeyNoKeyTest() throws MalformedURLException { 173 | System.setProperty(HUB, "https://ondemand.saucelabs.com:443"); 174 | assertNull(new Hub().getPassword(), null); 175 | } 176 | 177 | @Test(expectedExceptions = InvalidHubException.class) 178 | public void getKeyOnlyKeyTest() throws MalformedURLException { 179 | System.setProperty(HUB, "https://sauceaccesskey@ondemand.saucelabs.com:443"); 180 | new Hub().getPassword(); 181 | } 182 | 183 | @Test 184 | public void getCredsUrlSauceTest() throws MalformedURLException { 185 | System.setProperty(HUB, "https://sauceusername:sauceaccesskey@ondemand.saucelabs.com:443"); 186 | assertEquals(new Hub().getUsername(), "sauceusername"); 187 | assertEquals(new Hub().getPassword(), "sauceaccesskey"); 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /src/test/java/unit/RequestTest.java: -------------------------------------------------------------------------------- 1 | package unit; 2 | 3 | import com.coveros.selenified.services.Request; 4 | import com.google.gson.JsonArray; 5 | import com.google.gson.JsonObject; 6 | import org.testng.annotations.Test; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | import static org.testng.Assert.*; 12 | 13 | public class RequestTest { 14 | 15 | @Test 16 | public void checkJsonDataRequestTest() { 17 | JsonObject json = new JsonObject(); 18 | assertEquals(new Request().setJsonPayload(json).getJsonPayload(), json); 19 | } 20 | 21 | @Test 22 | public void checkJsonDataMultipartRequestTest() { 23 | JsonObject json = new JsonObject(); 24 | assertEquals(new Request().setJsonPayload(json).getMultipartData(), null); 25 | } 26 | 27 | @Test 28 | public void checkJsonDataParamsRequestTest() { 29 | JsonObject json = new JsonObject(); 30 | assertEquals(new Request().setJsonPayload(json).getUrlParams(), null); 31 | } 32 | 33 | @Test 34 | public void checkJsonDataDataRequestTest() { 35 | JsonObject json = new JsonObject(); 36 | json.addProperty("name", "john"); 37 | assertEquals(new Request().setJsonPayload(json).getJsonPayload(), json); 38 | } 39 | 40 | @Test 41 | public void checkJsonArrayRequestTest() { 42 | JsonArray json = new JsonArray(); 43 | assertEquals(new Request().setJsonPayload(json).getJsonPayload(), json); 44 | } 45 | 46 | @Test 47 | public void checkJsonArrayMultipartRequestTest() { 48 | JsonArray json = new JsonArray(); 49 | assertEquals(new Request().setJsonPayload(json).getMultipartData(), null); 50 | } 51 | 52 | @Test 53 | public void checkJsonArrayParamsRequestTest() { 54 | JsonArray json = new JsonArray(); 55 | assertEquals(new Request().setJsonPayload(json).getUrlParams(), null); 56 | } 57 | 58 | @Test 59 | public void checkJsonArrayDataRequestTest() { 60 | JsonArray json = new JsonArray(); 61 | json.add("john"); 62 | json.add("smith"); 63 | assertEquals(new Request().setJsonPayload(json).getJsonPayload(), json); 64 | } 65 | 66 | @Test 67 | public void checkMultipartRequestTest() { 68 | Map params = new HashMap<>(); 69 | assertEquals(new Request().setMultipartData(params).getMultipartData(), params); 70 | } 71 | 72 | @Test 73 | public void checkMultipartParamsRequestTest() { 74 | Map params = new HashMap<>(); 75 | assertEquals(new Request().setMultipartData(params).getUrlParams(), null); 76 | } 77 | 78 | @Test 79 | public void checkMultipartJsonRequestTest() { 80 | Map params = new HashMap<>(); 81 | assertEquals(new Request().setMultipartData(params).getJsonPayload(), null); 82 | } 83 | 84 | @Test 85 | public void checkMultipartDataRequestTest() { 86 | Map params = new HashMap<>(); 87 | params.put("name", "john"); 88 | assertEquals(new Request().setMultipartData(params).getMultipartData(), params); 89 | } 90 | 91 | @Test 92 | public void checkParamsRequestTest() { 93 | Map params = new HashMap<>(); 94 | assertEquals(new Request().setUrlParams(params).getUrlParams(), params); 95 | } 96 | 97 | @Test 98 | public void checkParamsJsonRequestTest() { 99 | Map params = new HashMap<>(); 100 | assertEquals(new Request().setUrlParams(params).getJsonPayload(), null); 101 | } 102 | 103 | @Test 104 | public void checkParamsMultipartRequestTest() { 105 | Map params = new HashMap<>(); 106 | assertEquals(new Request().setUrlParams(params).getMultipartData(), null); 107 | } 108 | 109 | @Test 110 | public void checkParamsDataRequestTest() { 111 | Map params = new HashMap<>(); 112 | params.put("name", "john"); 113 | assertEquals(new Request().setUrlParams(params).getUrlParams(), params); 114 | } 115 | 116 | @Test 117 | public void checkJsonObjectIsDataTest() { 118 | JsonObject json = new JsonObject(); 119 | assertTrue(new Request().setJsonPayload(json).isPayload()); 120 | } 121 | 122 | @Test 123 | public void checkJsonArrayIsDataTest() { 124 | JsonArray json = new JsonArray(); 125 | assertTrue(new Request().setJsonPayload(json).isPayload()); 126 | } 127 | 128 | @Test 129 | public void checkMultipartIsDataTest() { 130 | Map params = new HashMap<>(); 131 | assertTrue(new Request().setMultipartData(params).isPayload()); 132 | } 133 | 134 | @Test 135 | public void checkParamsIsDataTest() { 136 | Map params = new HashMap<>(); 137 | assertFalse(new Request().setUrlParams(params).isPayload()); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/test/java/unit/ResponseTest.java: -------------------------------------------------------------------------------- 1 | package unit; 2 | 3 | import com.coveros.selenified.services.Response; 4 | import com.google.gson.JsonArray; 5 | import com.google.gson.JsonObject; 6 | import org.testng.annotations.Test; 7 | 8 | import static org.testng.Assert.assertFalse; 9 | import static org.testng.Assert.assertTrue; 10 | 11 | public class ResponseTest { 12 | 13 | @Test 14 | public void defaultIsDataTest() { 15 | Response response = new Response(null, null, 0, null, null, null); 16 | assertFalse(response.isData()); 17 | } 18 | 19 | @Test 20 | public void IsDataObjectTest() { 21 | Response response = new Response(null, null, 0, new JsonObject(), null, null); 22 | assertTrue(response.isData()); 23 | } 24 | 25 | @Test 26 | public void IsDataArrayTest() { 27 | Response response = new Response(null, null, 0, null, new JsonArray(), null); 28 | assertTrue(response.isData()); 29 | } 30 | 31 | @Test 32 | public void IsDataBothTest() { 33 | Response response = new Response(null, null, 0, new JsonObject(), new JsonArray(), null); 34 | assertTrue(response.isData()); 35 | } 36 | } -------------------------------------------------------------------------------- /src/test/java/unit/SauceTest.java: -------------------------------------------------------------------------------- 1 | package unit; 2 | 3 | import com.coveros.selenified.Browser; 4 | import com.coveros.selenified.Capabilities; 5 | import com.coveros.selenified.exceptions.InvalidBrowserException; 6 | import com.coveros.selenified.exceptions.InvalidHubException; 7 | import com.coveros.selenified.exceptions.InvalidProxyException; 8 | import com.coveros.selenified.exceptions.InvalidSauceException; 9 | import com.coveros.selenified.utilities.Sauce; 10 | import org.openqa.selenium.Platform; 11 | import org.openqa.selenium.remote.DesiredCapabilities; 12 | import org.testng.annotations.Test; 13 | 14 | import java.net.MalformedURLException; 15 | 16 | import static com.coveros.selenified.utilities.Property.HUB; 17 | import static org.testng.Assert.assertEquals; 18 | import static org.testng.Assert.assertFalse; 19 | import static org.testng.Assert.assertTrue; 20 | import static unit.CapabilitiesTest.getBasicDesiredCapabilities; 21 | 22 | public class SauceTest extends SaveProperties { 23 | 24 | @Test 25 | public void isSauceNoHubTest() { 26 | assertFalse(Sauce.isSauce()); 27 | } 28 | 29 | @Test 30 | public void isSauceNotSauceTest() { 31 | System.setProperty(HUB, "Hello World"); 32 | assertFalse(Sauce.isSauce()); 33 | } 34 | 35 | @Test 36 | public void isSauceNotSauceURLTest() { 37 | System.setProperty(HUB, "http://localhost:4444"); 38 | assertFalse(Sauce.isSauce()); 39 | } 40 | 41 | @Test 42 | public void isSauceSauceTest() { 43 | System.setProperty(HUB, "https://sauceusername:sauceaccesskey@ondemand.saucelabs.com:443"); 44 | assertTrue(Sauce.isSauce()); 45 | } 46 | 47 | @Test(expectedExceptions = InvalidHubException.class) 48 | public void getSauceConnectionEmptyTest() throws MalformedURLException { 49 | new Sauce().getSauceConnection(); 50 | } 51 | 52 | @Test(expectedExceptions = InvalidSauceException.class) 53 | public void getSauceConnectionBadTest() throws MalformedURLException { 54 | System.setProperty(HUB, "https://saucelabs.com:443"); 55 | new Sauce().getSauceConnection(); 56 | } 57 | 58 | @Test 59 | public void getSauceConnectionTest() throws MalformedURLException { 60 | System.setProperty(HUB, "https://sauceusername:sauceaccesskey@ondemand.saucelabs.com:443"); 61 | new Sauce().getSauceConnection(); 62 | } 63 | 64 | @Test 65 | public void setupSauceCapabilitiesNoSauceTest() throws InvalidProxyException, InvalidBrowserException { 66 | // what we expect 67 | DesiredCapabilities expectedDesiredCapabilities = getBasicDesiredCapabilities("chrome"); 68 | // what we're getting 69 | Capabilities capabilities = new Capabilities(new Browser("Chrome")); 70 | Sauce.setupSauceCapabilities(capabilities.getDesiredCapabilities()); 71 | assertEquals(capabilities.getDesiredCapabilities(), expectedDesiredCapabilities); 72 | } 73 | 74 | @Test 75 | public void setupSauceCapabilitiesChromeTest() throws InvalidProxyException, InvalidBrowserException { 76 | System.setProperty(HUB, "ondemand.saucelabs.com"); 77 | // what we expect 78 | DesiredCapabilities expectedDesiredCapabilities = getBasicDesiredCapabilities("chrome"); 79 | expectedDesiredCapabilities.setCapability("seleniumVersion", "3.141.59"); 80 | // what we're getting 81 | Capabilities capabilities = new Capabilities(new Browser("Chrome")); 82 | Sauce.setupSauceCapabilities(capabilities.getDesiredCapabilities()); 83 | assertEquals(capabilities.getDesiredCapabilities(), expectedDesiredCapabilities); 84 | } 85 | 86 | @Test 87 | public void setupSauceCapabilitiesIETest() throws InvalidProxyException, InvalidBrowserException { 88 | System.setProperty(HUB, "ondemand.saucelabs.com"); 89 | // what we expect 90 | DesiredCapabilities expectedDesiredCapabilities = getBasicDesiredCapabilities("internet explorer"); 91 | expectedDesiredCapabilities.setPlatform(Platform.WINDOWS); 92 | expectedDesiredCapabilities.setAcceptInsecureCerts(false); 93 | expectedDesiredCapabilities.setCapability("seleniumVersion", "3.141.59"); 94 | expectedDesiredCapabilities.setCapability("iedriverVersion", "3.141.59"); 95 | // what we're getting 96 | Capabilities capabilities = new Capabilities(new Browser("internetExplorer")); 97 | Sauce.setupSauceCapabilities(capabilities.getDesiredCapabilities()); 98 | assertEquals(capabilities.getDesiredCapabilities(), expectedDesiredCapabilities); 99 | } 100 | } -------------------------------------------------------------------------------- /src/test/java/unit/SaveProperties.java: -------------------------------------------------------------------------------- 1 | package unit; 2 | 3 | import org.testng.ITestContext; 4 | import org.testng.annotations.AfterClass; 5 | import org.testng.annotations.AfterMethod; 6 | import org.testng.annotations.BeforeClass; 7 | import org.testng.annotations.BeforeMethod; 8 | 9 | import java.io.*; 10 | 11 | import static com.coveros.selenified.utilities.Property.*; 12 | 13 | public class SaveProperties { 14 | protected static final String SELENIFIED = System.getProperty("alt.build.dir") + "/test-classes/selenified.properties"; 15 | 16 | private String setDefaultWait = null; 17 | private String setDefaultPoll = null; 18 | private String setGeneratePDF = null; 19 | private String setPackageResults = null; 20 | private String setHub = null; 21 | private String setProxy = null; 22 | private String setAppUrl = null; 23 | private String setBrowser = null; 24 | private String setHeadless = null; 25 | private String setOptions = null; 26 | private String setBuildName = null; 27 | 28 | File propertiesFile = new File(SELENIFIED); 29 | File savePropertiesFile = new File(SELENIFIED + ".tmp"); 30 | 31 | @BeforeClass(alwaysRun = true) 32 | public void saveProperties() { 33 | if (System.getProperty(DEFAULT_WAIT) != null) { 34 | setDefaultWait = System.getProperty(DEFAULT_WAIT); 35 | } 36 | if (System.getProperty(DEFAULT_POLL) != null) { 37 | setDefaultPoll = System.getProperty(DEFAULT_POLL); 38 | } 39 | if (System.getProperty(GENERATE_PDF) != null) { 40 | setGeneratePDF = System.getProperty(GENERATE_PDF); 41 | } 42 | if (System.getProperty(PACKAGE_RESULTS) != null) { 43 | setPackageResults = System.getProperty(PACKAGE_RESULTS); 44 | } 45 | if (System.getProperty(HUB) != null) { 46 | setHub = System.getProperty(HUB); 47 | } 48 | if (System.getProperty(PROXY) != null) { 49 | setProxy = System.getProperty(PROXY); 50 | } 51 | if (System.getProperty(APP_URL) != null) { 52 | setAppUrl = System.getProperty(APP_URL); 53 | } 54 | if (System.getProperty(BROWSER) != null) { 55 | setBrowser = System.getProperty(BROWSER); 56 | } 57 | if (System.getProperty(HEADLESS) != null) { 58 | setHeadless = System.getProperty(HEADLESS); 59 | } 60 | if (System.getProperty(OPTIONS) != null) { 61 | setOptions = System.getProperty(OPTIONS); 62 | } 63 | if (System.getProperty(BUILD_NAME) != null) { 64 | setBuildName = System.getProperty(BUILD_NAME); 65 | } 66 | propertiesFile.renameTo(savePropertiesFile); 67 | } 68 | 69 | @AfterClass(alwaysRun = true) 70 | public void restoreProperties() { 71 | if (setDefaultWait != null) { 72 | System.setProperty(DEFAULT_WAIT, setDefaultWait); 73 | } 74 | if (setDefaultPoll != null) { 75 | System.setProperty(DEFAULT_POLL, setDefaultPoll); 76 | } 77 | if (setGeneratePDF != null) { 78 | System.setProperty(GENERATE_PDF, setGeneratePDF); 79 | } 80 | if (setPackageResults != null) { 81 | System.setProperty(PACKAGE_RESULTS, setPackageResults); 82 | } 83 | if (setHub != null) { 84 | System.setProperty(HUB, setHub); 85 | } 86 | if (setProxy != null) { 87 | System.setProperty(PROXY, setProxy); 88 | } 89 | if (setAppUrl != null) { 90 | System.setProperty(APP_URL, setAppUrl); 91 | } 92 | if (setBrowser != null) { 93 | System.setProperty(BROWSER, setBrowser); 94 | } 95 | if (setHeadless != null) { 96 | System.setProperty(HEADLESS, setHeadless); 97 | } 98 | if (setOptions != null) { 99 | System.setProperty(OPTIONS, setOptions); 100 | } 101 | if (setBuildName != null) { 102 | System.setProperty(BUILD_NAME, setBuildName); 103 | } 104 | savePropertiesFile.renameTo(propertiesFile); 105 | } 106 | 107 | @BeforeMethod(alwaysRun = true) 108 | @AfterMethod(alwaysRun = true) 109 | public void clearProperties(ITestContext context) { 110 | System.clearProperty(DEFAULT_WAIT); 111 | System.clearProperty(DEFAULT_POLL); 112 | System.clearProperty(GENERATE_PDF); 113 | System.clearProperty(PACKAGE_RESULTS); 114 | System.clearProperty(HUB); 115 | System.clearProperty(PROXY); 116 | System.clearProperty(APP_URL); 117 | context.removeAttribute(this.getClass().getName() + APP_URL); 118 | System.clearProperty(BROWSER); 119 | System.clearProperty(HEADLESS); 120 | System.clearProperty(OPTIONS); 121 | System.clearProperty(BUILD_NAME); 122 | 123 | if (new File(SELENIFIED).exists()) { 124 | new File(SELENIFIED).delete(); 125 | } 126 | deleteDirectory(new File("directory")); 127 | } 128 | 129 | void createPropertiesFile(String content) throws IOException { 130 | BufferedWriter writer = new BufferedWriter(new FileWriter(SELENIFIED)); 131 | writer.write(content); 132 | writer.close(); 133 | } 134 | 135 | boolean deleteDirectory(File directoryToBeDeleted) { 136 | File[] allContents = directoryToBeDeleted.listFiles(); 137 | if (allContents != null) { 138 | for (File file : allContents) { 139 | deleteDirectory(file); 140 | } 141 | } 142 | return directoryToBeDeleted.delete(); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/test/java/unit/ServicesAssertMatchesTest.java: -------------------------------------------------------------------------------- 1 | package unit; 2 | 3 | import com.coveros.selenified.Browser; 4 | import com.coveros.selenified.Capabilities; 5 | import com.coveros.selenified.exceptions.InvalidBrowserException; 6 | import com.coveros.selenified.exceptions.InvalidProxyException; 7 | import com.coveros.selenified.services.Response; 8 | import com.coveros.selenified.utilities.Reporter; 9 | import com.google.gson.JsonArray; 10 | import com.google.gson.JsonObject; 11 | import org.testng.annotations.AfterMethod; 12 | import org.testng.annotations.BeforeMethod; 13 | import org.testng.annotations.Test; 14 | 15 | import java.io.File; 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | public class ServicesAssertMatchesTest { 20 | 21 | private Reporter reporter; 22 | private File directory; 23 | private File file; 24 | 25 | @BeforeMethod(alwaysRun = true) 26 | public void createFile() throws InvalidBrowserException, InvalidProxyException { 27 | reporter = 28 | new Reporter("directory", "file", new Capabilities(new Browser("None")), null, null, null, null, null, null); 29 | directory = new File("directory"); 30 | file = new File("directory", "file.html"); 31 | } 32 | 33 | @AfterMethod(alwaysRun = true) 34 | public void deleteFile() { 35 | file.delete(); 36 | directory.delete(); 37 | } 38 | 39 | @Test 40 | public void confirmEqualsCodePassTest() { 41 | JsonObject json = new JsonObject(); 42 | json.addProperty("name", "john"); 43 | Response response = new Response(reporter, null, 5, json, null, null); 44 | response.assertMatches().code("(\\d)"); 45 | } 46 | 47 | @Test(expectedExceptions = AssertionError.class) 48 | public void confirmEqualsCodeFailTest() { 49 | JsonObject json = new JsonObject(); 50 | json.addProperty("name", "john"); 51 | Response response = new Response(reporter, null, 5, json, null, null); 52 | response.assertMatches().code("([0-3])"); 53 | } 54 | 55 | @Test 56 | public void confirmEqualsMessagePassTest() { 57 | Response response = new Response(reporter, null, 5, new JsonObject(), null, "Some message"); 58 | response.assertMatches().message("([\\w\\s]*)"); 59 | } 60 | 61 | @Test(expectedExceptions = AssertionError.class) 62 | public void confirmEqualsMessageFailTest() { 63 | Response response = new Response(reporter, null, 5, new JsonObject(), null, "SOME MESSAGE"); 64 | response.assertMatches().message("([a-z]*)"); 65 | } 66 | 67 | @Test(expectedExceptions = AssertionError.class) 68 | public void confirmEqualsMessageNullTest() { 69 | Response response = new Response(reporter, null, 5, new JsonObject(), null, null); 70 | response.assertMatches().message(""); 71 | } 72 | 73 | @Test(expectedExceptions = NullPointerException.class) 74 | public void confirmEqualsCrumbsNothing() { 75 | Response response = new Response(reporter, null, 5, null, null, null); 76 | response.assertMatches().nestedValue(null, "name"); 77 | } 78 | 79 | @Test(expectedExceptions = AssertionError.class) 80 | public void confirmEqualsCrumbsNoJsonObject() { 81 | Response response = new Response(reporter, null, 5, null, null, null); 82 | response.assertMatches().nestedValue(new ArrayList<>(), "name"); 83 | } 84 | 85 | @Test(expectedExceptions = NullPointerException.class) 86 | public void confirmEqualsCrumbsNoCrumbs() { 87 | Response response = new Response(reporter, null, 5, new JsonObject(), null, null); 88 | response.assertMatches().nestedValue(null, "name"); 89 | } 90 | 91 | @Test(expectedExceptions = AssertionError.class) 92 | public void confirmEqualsCrumbsCrumbsNotExist() { 93 | JsonObject child = new JsonObject(); 94 | child.addProperty("first", "john"); 95 | child.addProperty("last", "smith"); 96 | JsonArray json = new JsonArray(); 97 | json.add(child); 98 | Response response = new Response(reporter, null, 5, null, json, null); 99 | List list = new ArrayList<>(); 100 | list.add("name"); 101 | response.assertMatches().nestedValue(list, "john"); 102 | } 103 | 104 | @Test(expectedExceptions = AssertionError.class) 105 | public void confirmEqualsCrumbsCrumbsNotJsonObject() { 106 | JsonArray array = new JsonArray(); 107 | array.add("john"); 108 | array.add("jon"); 109 | JsonObject json = new JsonObject(); 110 | json.add("first", array); 111 | json.addProperty("last", "smith"); 112 | Response response = new Response(reporter, null, 5, json, null, null); 113 | List list = new ArrayList<>(); 114 | list.add("first"); 115 | list.add("last"); 116 | response.assertMatches().nestedValue(list, "john"); 117 | } 118 | 119 | @Test 120 | public void confirmEqualsCrumbsMatch() { 121 | JsonObject json = new JsonObject(); 122 | json.addProperty("first", "john"); 123 | json.addProperty("last", "smith"); 124 | Response response = new Response(reporter, null, 5, json, null, null); 125 | List list = new ArrayList<>(); 126 | list.add("first"); 127 | response.assertMatches().nestedValue(list, "john"); 128 | } 129 | 130 | @Test(expectedExceptions = AssertionError.class) 131 | public void confirmEqualsCrumbsNoMatch() { 132 | JsonObject json = new JsonObject(); 133 | json.addProperty("first", "john"); 134 | json.addProperty("last", "smith"); 135 | Response response = new Response(reporter, null, 5, json, null, null); 136 | List list = new ArrayList<>(); 137 | list.add("first"); 138 | response.assertMatches().nestedValue(list, "janice"); 139 | } 140 | } -------------------------------------------------------------------------------- /src/test/java/unit/TestCaseTest.java: -------------------------------------------------------------------------------- 1 | package unit; 2 | 3 | import com.coveros.selenified.utilities.TestCase; 4 | import org.testng.annotations.Test; 5 | 6 | import java.lang.reflect.Method; 7 | 8 | import static org.testng.Assert.assertEquals; 9 | import static org.testng.Assert.assertTrue; 10 | 11 | public class TestCaseTest { 12 | 13 | @Test 14 | public void getRandomStringLengthTest() { 15 | assertEquals(TestCase.getRandomString(0).length(), 0); 16 | assertEquals(TestCase.getRandomString(0), ""); 17 | assertEquals(TestCase.getRandomString(999).length(), 999); 18 | assertTrue(TestCase.getRandomString(999).matches("^[A-Za-z0-9]{999}$")); 19 | assertEquals(TestCase.getRandomString(-1).length(), 0); 20 | assertEquals(TestCase.getRandomString(-1), ""); 21 | } 22 | 23 | @Test 24 | public void removeNonWordCharactersTest() { 25 | assertEquals(TestCase.removeNonWordCharacters(null), null); 26 | assertEquals(TestCase.removeNonWordCharacters(""), ""); 27 | assertEquals(TestCase.removeNonWordCharacters("hello world"), "helloworld"); 28 | assertEquals(TestCase.removeNonWordCharacters("hello-world"), "helloworld"); 29 | assertEquals(TestCase.removeNonWordCharacters("hello_world"), "helloworld"); 30 | assertEquals(TestCase.removeNonWordCharacters("hello`~!@#$%^&*()world"), "helloworld"); 31 | assertEquals(TestCase.removeNonWordCharacters("hello[]\\{}|;':\",./<>?world"), "helloworld"); 32 | } 33 | 34 | @Test 35 | public void getTestNameNullTest(Method method) { 36 | assertEquals(TestCase.getTestName("UnitTests", "helloWorld"), "UnitTests.helloWorld"); 37 | assertEquals(TestCase.getTestName("UnitTests", "helloWorld", null), "UnitTests.helloWorld"); 38 | assertTrue(TestCase.getTestName("UnitTests", "helloWorld", new Object[]{}).startsWith("UnitTests.helloWorld")); 39 | assertTrue(TestCase.getTestName( "UnitTests", "helloWorld", new Object[]{null}).startsWith("UnitTests.helloWorld")); 40 | 41 | } 42 | 43 | @Test 44 | public void getTestNameTest(Method method) { 45 | assertEquals(TestCase.getTestName(method), "unit.TestCaseTest.getTestNameTest"); 46 | Object[] options = new Object[]{"Python", "public"}; 47 | assertEquals(TestCase.getTestName(method, options), 48 | "unit.TestCaseTest.getTestNameTestWithOptionPythonPublic"); 49 | options = new Object[]{"Python", null}; 50 | assertEquals(TestCase.getTestName(method, options), 51 | "unit.TestCaseTest.getTestNameTestWithOptionPython"); 52 | assertEquals(TestCase.getTestName("UnitTests", "helloWorld", "python"), 53 | "UnitTests.helloWorldWithOptionPython"); 54 | assertEquals(TestCase.getTestName("UnitTests", "helloWorld", "visual basic"), 55 | "UnitTests.helloWorldWithOptionVisualbasic"); 56 | assertEquals(TestCase.getTestName("UnitTests", "helloWorld", "Python"), 57 | "UnitTests.helloWorldWithOptionPython"); 58 | assertEquals(TestCase.getTestName("UnitTests", "helloWorld", "Python", "Perl"), 59 | "UnitTests.helloWorldWithOptionPythonPerl"); 60 | assertEquals(TestCase 61 | .getTestName("UnitTests", "helloWorld", "Python", "Perl", "Bash", "Java", "Ruby", "Groovy", 62 | "Javascript", "PHP", "Scala", "Fortan", "Lisp", "COBOL", "Erlang", "Pacal", "Haskell", "Swift", 63 | "Elixir", "BASIC", "Tcl", "Rust", "Visual Basic", "Ceylon", "Cobra", "Forth", "Curry", "COMOL", 64 | "Gosu", "Powershell", "Squeak", "Gambas"), 65 | "UnitTests.helloWorldWithOptionPythonPerlBashJavaRubyGroovyJavascriptPHPScalaFortanLispCOBOLErlangPacalHaskellSwiftElixirBASICTclRustVisualBasicCeylonCobraForthCurryCOMOLGosuPowershellSqueakGambas"); 66 | String testName = TestCase 67 | .getTestName("UnitTests", "helloWorld", "Python", "Perl", "Bash", "Java", "Ruby", "Groovy", 68 | "Javascript", "PHP", "Scala", "Fortan", "Lisp", "COBOL", "Erlang", "Pacal", "Haskell", "Swift", 69 | "Elixir", "BASIC", "Tcl", "Rust", "Visual Basic", "Ceylon", "Cobra", "Forth", "Curry", "COMOL", 70 | "Gosu", "Powershell", "Squeak", "Gambas", "Euphoria", "Fantom", "Assembly"); 71 | assertTrue(testName.matches("^UnitTests\\.helloWorld@[0-9a-f]+$")); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/test/resources/selenified.properties: -------------------------------------------------------------------------------- 1 | # connection 2 | hub= 3 | proxy= 4 | appURL= 5 | # browser 6 | browser= 7 | headless=true 8 | options= 9 | # logging 10 | defaultWait=5 11 | defaultPoll=50 12 | generatePDF=false 13 | packageResults=false --------------------------------------------------------------------------------