-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added better examples of custom steps definitions and updated the gin…
…gerspec dependency in pom
- Loading branch information
jose.fernandez
committed
Sep 10, 2019
1 parent
3f22ca4
commit 26a4083
Showing
5 changed files
with
75 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 67 additions & 39 deletions
106
...etype-resources/src/test/java/__groupId__/__artifactId__/specs/CustomStepsDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,97 @@ | ||
package ${groupId}.${artifactId}.specs; | ||
|
||
import com.privalia.qa.specs.*; | ||
import com.privalia.qa.utils.ThreadProperty; | ||
import cucumber.api.java.en.Given; | ||
import org.openqa.selenium.remote.RemoteWebDriver; | ||
|
||
/** | ||
* Extending the {@link BaseGSpec} class from the bdt-lib allow us to | ||
* Extending the {@link BaseGSpec} class from the gingerspec allow us to | ||
* define custom step definitions for our project and at the same time | ||
* make use of the properties of the {@link CommonG} object | ||
*/ | ||
public class CustomStepsDefinition extends BaseGSpec { | ||
|
||
GivenGSpec commonspecGiven; | ||
WhenGSpec commonspecWhen; | ||
ThenGSpec commonspecThen; | ||
BigDataGSpec commonspecBigData; | ||
SeleniumGSpec commonspecSelenium; | ||
|
||
BigDataGSpec bigDataGSpec; | ||
FileParserGSpec fileParserGSpec; | ||
KafkaGSpec kafkaGSpec; | ||
RestSpec restSpec; | ||
SeleniumGSpec seleniumGSpec; | ||
SoapServiceGSpec soapServiceGSpec; | ||
SqlDatabaseGSpec sqlDatabaseGSpec; | ||
SshGSpec sshGSpec; | ||
UtilsGSpec utilsGSpec; | ||
|
||
/** | ||
* Example how to inherit the needed objects from bdt-lib | ||
* Example of how to inherit the needed objects from gingerspec | ||
* @param spec | ||
*/ | ||
public CustomStepsDefinition(CommonG spec) { | ||
|
||
/** | ||
* the CommonG object with "atomic" methods and interface to utils files | ||
*/ | ||
this.commonspec = spec; | ||
|
||
/** | ||
* common given gherkin steps: ssh, rest, etc | ||
*/ | ||
commonspecGiven = new GivenGSpec(this.commonspec); | ||
/* Access all functions for working with Big data functionality */ | ||
bigDataGSpec = new BigDataGSpec(this.commonspec); | ||
|
||
/* Access all functions for handling and parsing text files */ | ||
fileParserGSpec = new FileParserGSpec(this.commonspec); | ||
|
||
/* Access all functions for working with kafka */ | ||
kafkaGSpec = new KafkaGSpec(this.commonspec); | ||
|
||
/* Access all functions for working with REST services */ | ||
restSpec = new RestSpec(this.commonspec); | ||
|
||
/* Access all functions for working with selenium */ | ||
seleniumGSpec = new SeleniumGSpec(this.commonspec); | ||
|
||
/** | ||
* common when gherkin steps: ssh, rest, etc | ||
*/ | ||
commonspecWhen = new WhenGSpec(this.commonspec); | ||
/* Access all functions for working with SOAP web services */ | ||
soapServiceGSpec = new SoapServiceGSpec(this.commonspec); | ||
|
||
/** | ||
* common then gherkin steps: ssh, rest, etc | ||
*/ | ||
commonspecThen = new ThenGSpec(this.commonspec); | ||
/* Access all functions for working with relational databases */ | ||
sqlDatabaseGSpec = new SqlDatabaseGSpec(this.commonspec); | ||
|
||
/** | ||
* common BigData gherkin steps: Cassandra, MongoDB, elasticsearch, etc | ||
*/ | ||
commonspecBigData = new BigDataGSpec(this.commonspec); | ||
/* Access all functions for running bash commands and establishing SSH connections */ | ||
sshGSpec = new SshGSpec(this.commonspec); | ||
|
||
/** | ||
* new Selenium steps | ||
*/ | ||
commonspecSelenium = new SeleniumGSpec(this.commonspec); | ||
/* Access all other useful functions/operations */ | ||
utilsGSpec = new UtilsGSpec(this.commonspec); | ||
|
||
} | ||
|
||
|
||
/** | ||
* Step example. You can define your own steps that can be used in the feature files in case | ||
* you have a very specific use case that is not covered in the library | ||
* This is an example of a custom step. You can merge several low-level gingerspec steps into a | ||
* higher-level step just by calling the underlying functions. | ||
* | ||
* To help you with this, execute your tests with -DSHOW_STACK_INFO. This will provide you with information | ||
* about what functions of gingerspec are being called and with what arguments | ||
* | ||
* @throws Throwable Throwable | ||
*/ | ||
@Given("^I want to go to disneyland$") | ||
public void mytest() { | ||
RemoteWebDriver d = this.commonspec.getDriver(); | ||
d.get("https://www.disney.com"); | ||
@Given("^I verify the Interactions and Widgets sections are present$") | ||
public void iVerifyTheInteractionsAndWidgetsSectionsArePresent() throws Throwable { | ||
seleniumGSpec.setupApp("demoqa.com:80"); | ||
seleniumGSpec.seleniumBrowse(null,"/"); | ||
seleniumGSpec.assertSeleniumNElementExists(2,"class","widget-title"); | ||
utilsGSpec.idleWait(1); | ||
} | ||
|
||
|
||
} | ||
/** | ||
* This is an example of a custom step. You can merge several low-level gingerspec steps into a | ||
* higher-level step just by calling the underlying functions. | ||
* | ||
* to access variables !{} use ThreadProperty.get(variable) | ||
* to access variables ${} use System.getProperty(variable) | ||
* | ||
* @throws Throwable Throwable | ||
*/ | ||
@Given("^I verify that a successful response with a valid body is returned$") | ||
public void iVerifyThatASuccessfulResponseWithAValidBodyIsReturned() throws Throwable { | ||
restSpec.setupApp("securely","jsonplaceholder.typicode.com:443"); | ||
restSpec.sendRequestNoDataTable("GET","/posts",null,null,null); | ||
restSpec.assertResponseStatusLength(200,null); | ||
restSpec.saveElementEnvironment(null,"$.[0].userId","USER_ID"); | ||
utilsGSpec.checkValue(ThreadProperty.get("USER_ID"),"matches","1"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters