Skip to content

LevanKerdikashvili/appiumProject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

appium - test automation (Front - Android/iOS)


Technology:

  • Automation Framework: Appium
  • Build tool: Maven
  • Bundled Tools: TestNG
  • Language: Java
  • Report: extent
  • Project Structure: Page object Model(POM)

Prerequisite:


Android Studio Setup (emulators + Real Device)

Download and install Android Studio based on your preferred OS. Then set your ANDROID_HOME by follow this steps:

Setting ANDROID_HOME Variable

This guide will walk you through setting the ANDROID_HOME variable on both Windows and macOS. The ANDROID_HOME variable is used by various tools and IDEs for locating the Android SDK installation directory.

  1. Locate your Android SDK installation directory. By default, it's typically installed in C:\Users\YourUsername\AppData\Local\Android\Sdk.

  2. Right-click on "This PC" or "My Computer" and select "Properties".

  3. Click on "Advanced system settings" on the left side.

  4. In the System Properties window, go to the "Advanced" tab and click on the "Environment Variables" button at the bottom.

  5. In the Environment Variables window, under "System variables", click on "New".

  6. For the Variable Name, enter ANDROID_HOME.

  7. For the Variable Value, enter the path to your Android SDK installation directory (e.g., C:\Users\YourUsername\AppData\Local\Android\Sdk).

  8. Click "OK" to save the variable.

  9. Click "OK" again to close the Environment Variables window.

  10. You may need to restart your system for the changes to take effect, although restarting your command prompt or IDE may be sufficient.

Setting ANDROID_HOME on macOS

  1. Open Terminal.

  2. Run the command nano ~/.bash_profile to open your bash profile (you can also use ~/.zshrc if you are using Zsh).

  3. Add the following line at the end of the file:

export ANDROID_HOME=/Users/YourUsername/Library/Android/sdk

Replace /Users/YourUsername/Library/Android/sdk with the path to your Android SDK installation directory.

  1. Save the file by pressing Ctrl + X, then Y, and finally press Enter.

  2. To make the changes take effect, either restart Terminal or run source ~/.bash_profile in the terminal.

Remember to replace YourUsername with your actual username in the paths specified above.

Connecting a Real Device for Mobile App Testing with Appium

Enable Developer Mode on Your Device:

  1. For Android: Go to Settings > About phone > Software info, then tap "Build number" 7 times to enable Developer Options. Once enabled, go to Settings > Developer options and enable USB debugging.

Connect Your Device to the Computer:

  • Use a USB cable to connect your device to your computer.

Check Device Connection:

  • Open a terminal or command prompt.
    • Run adb devices. Your device should be listed. (for Android)
    • Run xcrun xctrace list devices. Your device should be listed. (for iOS)

Additional variables

For more comfortable, you will also need it during the work process set next variables platform-tools
cmdline-tools
cmdline-tools/bin
emulator

for MAC

export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/cmdline-tools:$PATH
export PATH=$ANDROID_HOME/cmdline-tools/bin:$PATH
export PATH=$ANDROID_HOME/emulator:$PATH

for Windows

Use the process which is described above about how to set ANDROID_HOME

warning! if you use old android studio version, you needs:
platform-tools
tools
tools/bin
emulator
instead of
platform-tools
cmdline-tools
cmdline-tools/bin
emulator


Setup Android Emulator

Open Android Studio -> More Actions -> Virtual Device Manager -> Create device -> Choose any type of device you want (in this tutorial I use Pixel 4 with Google Play) -> Choose your Android version which we have installed in previous steps (API 33 with Google Play).

Run your previously created Android emulator.


Appium installation

Open your terminal or cmd then enter command and wait for installation to finish
npm install -g appium@next or will be better npm install -g appium@2.5

Install Appium 2 driver for Android using terminal
appium driver install uiautomator2

Check if uiautomator2 driver is installed
appium driver list

Install the plugin using Appium's plugin CLI, either as a named plugin or via NPM:
appium plugin install --source=npm appium-device-farm

appium plugin install --source=npm appium-dashboard

The plugin will not be active unless turned on when invoking the Appium server. See "Argument options" below
appium server -ka 800 --use-plugins=device-farm,appium-dashboard -pa /wd/hub --plugin-device-farm-platform=android
You can define as well device type "android" , "ios" or "both"


you can block/unblock devices from Dashboard manually. These devices will not be picked up for automation. Once automation picks the device user cannot manually unblock, it's responsible for the automation script. dashboard will be: localhost:4723/device-farm for more information check Appium Device Farm Doc.

How to use appium inspector:

Set Driver Capabilities

In order for Appium to be able to connect to your device and app, you need to fill in some information about your testing environment such as device and application information. Find your Android emulator UDID by using terminal and enter this command:

adb devices // but if you use device-farm you don't need device UDID

Copy this JSON capabilities into your Appium Inspector (for ANDROID)

{ "platformName": "Android",
"appium:udid": "yourudid", // if you need this
"appium:appPackage": "com.google.android.youtube",
"appium:appActivity": "com.google.android.youtube.app.honeycomb.Shell$HomeActivity",
"appium:deviceName": "yourdevicename",
"appium:automationName": "UiAutomator2",
"appium:autoGrantPermissions": true
}

Copy this JSON capabilities into your Appium Inspector (for IOS)

{ "appium:platformName": "ios",
"appium:automationName": "XCUITest",
"appium:udid": "ios device udid",
"appium:forceEspressoRebuild": true,
"appium:printPageSourceOnFindFailure": true,
"appium:printPageSourceOnFindFailure": true
"appium:bundleId": "ios app bundle id"
}

Replace “yourudid” in “appium:udid” with your UDID which you found in this previous step.
Replace “yourdevicename” in “appium:deviceName” with you Android emulator name. You can find information about your device name in Android Studio -> Device Manager.

Pixel 4 API 33 is the name of my emulator device.
Actually there are 2 ways to set which application you will automate:
By using capability of “appium:app”, with this your apk is not pre-installed on your device and will be installed each time your test run. If you are using this type of capability then you don’t need to use “appium:appPackage” and “appium:appActivity” as we used in the previous steps.


Run the Automation Script:

  1. Prepare Emulator or real device
  2. Run Appium server
  3. check config.properties before execute
  4. Run the testng/*.xml file(s) or use mvn command mvn clean test -Dplatform=android or ios -Denv=dev or qa.
  5. After Complete the test execution Report will generate to "report" Folder if it will be enabled from config

Folder Structure

  • src/: Contains the source code of the project.

    • java/: Contains the Java source files.
      • uz.tbcBank: main package
        • Helpers: classes of Helpers
          • ExtendReport: The ExtentReport class is a helper class that provides methods for creating and managing ExtentReports objects for generating test reports
          • Config: The Config class loads a configuration file and provides a way to read its properties, with a singleton pattern implementation
          • Listener: It implements the ITestListener interface and overrides all of its methods
          • Utils: The Utils class contains various utility methods
        • Page/{teamName}/{moduleName}: Java class that contains locators and methods (Page Object)
        • test/: Contains the test source code files.
          • test/{teamName}/{moduleName}: Java class that contains test cases as methods and BaseTest.java
          • BaseTest : The BaseTest class in Java sets up and initializes the driver with desired capabilities for Android and iOS platforms
        • resources/app/{env}/app.apk: .apk file for testing
        • resources/{env}.xml: xml files which contains constants/strings depending on the environment
  • pom.xml: Maven configuration file for your project.

  • target/: Contains compiled classes and packaged artifacts (created after building the project).

  • README.md: This README file providing an overview of the project.

  • config.properties: common config data.

  • report: contains reporting files index.html (you can open it in any browser) + screenshots

  • app.log: contains logs

  • testng/*.xml: testng files

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages