Skip to content

Commit

Permalink
Merge pull request #2 from shankybnl/bdd-cucumber-tests
Browse files Browse the repository at this point in the history
Bdd cucumber tests
  • Loading branch information
shankybnl committed Mar 29, 2019
2 parents 76525d5 + 91fe8ec commit 228c544
Show file tree
Hide file tree
Showing 27 changed files with 729 additions and 22 deletions.
78 changes: 68 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Cheers!
*Single code base framework to test android and iOS app using appium. It is a boilerplate code. Clone it and you are good to go!*



## Framework with testng tests setup and execution ([cucumber BDD tests here](#cucumber-bdd-tests))

**Package : UITestFramework** : It includes the common classes (and methods) which are required by each test to perform actions. Below are classes in this package:

![image](UIAutomation/images/1.png)
Expand Down Expand Up @@ -84,21 +87,23 @@ findElements(By locator) - method to find all the elements of specific locator

**Package: IntegrationTests.coreLogic.android** : For each base coreLogic there would be corresponding android coreLogic (e.g. - AndroidLoginCoreLogic)
where abstract method declared in base class are defined. Corresponding base class, coreLogic will be extended by android coreLogic class. E.g. for LoginCoreLogic base class, AndroidLoginCoreLogic will extend LoginCoreLogic.
.

**Package: IntegrationTests.coreLogic.ios** : For each base coreLogic class there would be corresponding ios coreLogic class (e.g. - IOSLoginCoreLogic)
where abstract method declared in base class are defined.Corresponding base coreLogic class will be extended by ios coreLogic class. E.g. for LoginCoreLogic base class, IOSLoginCoreLogic will extend LoginCoreLogic.


**Package: IntegrationTests.coreLogic.tests** : This package contains all the tests. In each test there is instantiateHelpers(String invokeDriver) method which creates the object at
![image](UIAutomation/images/9.png)


**Package: tests.testngTests** : This package contains all the tests. In each test there is instantiateHelpers(String invokeDriver) method which creates the object at
runtime of the coreLogic classes required in the test. Object creation happens depending on the platform passed through invokeDriver parameter (android or ios). Then test calls methods defined in the coreLogic (of which object is created).

![image](UIAutomation/images/9.png)


###Javadoc of the project can be found in doc folder. It contains information all classes and methods.
### Javadoc of the project can be found in doc folder. It contains information all classes and methods.


#Execution flow of a Test
## Execution flow of test test

Below is execution flow with help of login test as example.

Expand Down Expand Up @@ -149,23 +154,76 @@ IOSLoginCoreLogic would be under iOS -> IOSLoginCoreLogic.
Similar thing should be done for element locators. There is no base folder in case of screens.For android locators, it would be under screens->android->AndroidLoginScreen.
For iOS locators, it would be under screens->ios->IOSLoginScreen.

#How to execute a test
##### How to execute a test

Maven is used as build tool (can be downloaded from [here](https://maven.apache.org/download.cgi)). pom.xml file is present in base directory which has all the required dependencies and code to invoke testng.xml file when executed from command line.

Connect your device to your machine or start the emulator.

*Note: start appium server on your machine if not included programatically*

######Run below commands to execute android test:
###### Run below commands to execute android testng test:

$ cd mobileautomationframework/
$ mvn test -Dos=android
$ mvn test -Dos=android -Dsurefire.suiteXmlFiles=testng.xml

*Include iOS app on which you want to run test. Provide its path in config.xml file (iOSAppPath=src/app/path-to-your-iOSfile). And write screen locators in IOSLoginScreen and methods in IOSLoginCorelogic. Now you are ready to run below commands.*

######Run below commands to execute iOS test:
###### Run below commands to execute iOS testng test:

$ cd mobileautomationframework/
$ mvn test -Dos=iOS
$ mvn test -Dos=iOS -Dsurefire.suiteXmlFiles=testng.xml

xxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Cucumber BDD tests

![image](UIAutomation/images/20.png)

**Package : cucumberIntegrationTests** :This package has sub-packages: screens and stepDefinitions. It also includes CucumberRunnerUtil class and CreateSessionCucumber class which are required to keep configurations and creating appium instance respectively.

![image](UIAutomation/images/21.png)

**Package: IntegrationTests.screens** : Classes in this package contains locators which are being used in coreLogic classes. Each page in mobile application is mapped to screen. E.g. for android login page, its AndroidLoginScreen. Segregated the locators on the bases of platform: android or iOS

**Package: IntegrationTests.screens.android** : Each screen on andriod app will be having as screen class under this package. It contains all the locators which are visible on that screen. E.g. - AndroidLoginScreen. Each android screen class extends GenericMethods.java.

**Package: IntegrationTests.screens.ios** : Each screen on ios app will be having as screen class under this package. It contains all the locators which are visible on that screen. E.g. - IOSLoginScreen etc. Each iOS screen class extends GenericMethods.java.

![image](UIAutomation/images/22.png)

**Package: stepDefinitions.common** : This package has all classes with common methods which can be used across android and iOS platform. It also has BaseSteps class which has initiation and appium driver creation for android or iOS platform.

**Package: stepDefinitions.android** : It should contain all the stepDefinitions for android features. e.g. AndroidLoginSteps

**Package: stepDefinitions.iOS** : It should contain all the stepDefinitions for iOS features. e.g. iOSLoginSteps

**CucumberRunnerUtil.java**: cucumberTestng.xml invokes this class. It has all the configuration for cucumber to execute tests and testng annotations to leverage their benefits.

![image](UIAutomation/images/23.png)

**CreateSessionCucumber.java** : Similar to [Create session class](**CreateSession.java) to create driver object and loading test data etc.

##### How to execute a test

Maven is used as build tool (can be downloaded from [here](https://maven.apache.org/download.cgi)). pom.xml file is present in base directory which has all the required dependencies and code to invoke testng.xml file when executed from command line.

Connect your device to your machine or start the emulator.

*Note: start appium server on your machine if not included programatically*

###### Run below commands to execute android testng test:

$ cd mobileautomationframework/
$ mvn test -Dos=android -Dsurefire.suiteXmlFiles=cucumberTestng.xml

*Include iOS app on which you want to run test. Provide its path in config.xml file (iOSAppPath=src/app/path-to-your-iOSfile). And write screen locators in IOSLoginScreen and methods in IOSLoginCorelogic. Now you are ready to run below commands.*

###### Run below commands to execute iOS testng test:

$ cd mobileautomationframework/
$ mvn test -Dos=iOS -Dsurefire.suiteXmlFiles=cucumberTestng.xml




Binary file added UIAutomation/.DS_Store
Binary file not shown.
Binary file modified UIAutomation/images/1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UIAutomation/images/20.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UIAutomation/images/21.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UIAutomation/images/22.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UIAutomation/images/23.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified UIAutomation/images/4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified UIAutomation/images/5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified UIAutomation/images/6.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified UIAutomation/images/7.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified UIAutomation/images/8.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified UIAutomation/images/9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions cucumberTestng.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="mobile-automation-framework">
<parameter name="os" value="${os}" />


<test name="automation-tests">
<classes>
<class name="cucumberIntegrationTests.CucumberRunnerUtil" />
</classes>
</test>
</suite>
40 changes: 39 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<name>MobileAutomationFramework</name>
<url>http://maven.apache.org</url>



<build><plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -19,7 +21,7 @@
<configuration>
<argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
Expand Down Expand Up @@ -122,6 +124,42 @@
</dependency>


<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>


</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ public void verifyLoginScenario(String userName, String password) throws Interru
androidLoginScreen.findElement(androidLoginScreen.signInButton).click();


Log.info("Login Successful");


// verify if "Get Started" button is displayed
androidLoginScreen.waitForVisibility(androidLoginScreen.startedButton);
Log.info("Login Successful");
androidLoginScreen.findElement(androidLoginScreen.startedButton).click();
androidLoginScreen.waitForVisibility(androidLoginScreen.titleBar);

Expand Down

0 comments on commit 228c544

Please sign in to comment.