Monday, August 12, 2019

Appium Setup and Running Test Script on Windows Machine

Appium Setup and Running Test Script on Windows Machine :


In this Post, we will learn how to do Appium setup:


Appium Setup with Eclipse: follow the below steps to setup Appium automation in eclipse:
1.      Java Installation:  
a.      Download JDK 8 from oracle site.
b.      Install JDK 8 .
c.      Set Java Path.
                                                    i.     Load the System Properties by rigxht clicking on My computer and click on properties
                                                   ii.     Click on Advanced Tab in the Properties Window
                                                  iii.     Scroll down in the System variables and find the PATH variable
                                                  iv.     Select the PATH variable and click the Edit button
                                                   v.     Add the Java installation path to the PATH variable
Example: C:\program files\Java\jdk1.6.0_22\bin 
Set JAVA_HOME in user variables and add the path
 C:\progra~2\Java\jdk1.6.0_22 

2.      Android Studio Installation:
a.      Download Android Studio from https://developer.android.com/studio
b.      Install the android studio
c.      Once installation complete set the Path by following the below steps:
                                                    i.     Right-click on ‘My Computer’ and select Properties. Go to Advanced system settings and select ‘Environmental Variables’ option.
                                                   ii.     Under the User Variable table, click New to open New User Variable dialog.
                                                  iii.     Put ANDROID_HOME as Variable name and provide the path of the SDK folder next to Variable value.
                                                  iv.     Click OK to close the dialog box.
                                                   v.     Go to the folder where SDK has been installed.
                                                  vi.     Inside the SDK folder look for ‘tools’ and ‘platform-tools’ folder.
                                                vii.     Copy the path for both tools and platform-tools.
                                               viii.     Open ‘Environmental Variables’ dialog box.
                                                  ix.     Go to System Variables table and locate the Path variable.
                                                   x.     Edit the path variable from ‘Edit system Variables’ dialog box.
                                                  xi.     Add the ‘tools’ and platform-tools’ folder’s full path, as shown below.
                                                xii.     Close the entire opened dialog box.
                                               xiii.     This configures the Android. However, to check open the command prompt.
                                               xiv.     Type the command ‘android’. This will open the Android SDK Manager dialog box
d.      This ensures that the android is configured properly.
3.      Appium Installation:

a.       Go to the link appium.io  - https://github.com/appium/appium-desktop/releases
b.       Click on “AppiumForWindows.zip” link 
c.       Download starts.
d.       Unzip the donwloaded zipped folder.
e.      Install the exe file “appium-installer”.

4.      Configure Appium:
a.      Open the Appium Desktop
b.      Provide the server ip as “127.0.0.1” and port ad “4723”
c.      Click on “Start Server” button
d.      Then it will start the server

5.      Enabling Developer Mode Options on Android Phone or Tablet

a.      Enabling Developer options
                                                    i.     Tap on the Main Menu icon.
                                                   ii.     Go to the Settings.
                                                  iii.     Scroll down to ‘About phone‘ and tap on it.
                                                  iv.     Scroll down to the bottom again, where you see ‘Build number’ (Your build number may vary). Tap On Build number Seven (7) times. After the third tap, you’ll see a playful dialog that says you’re four taps away from being a developer. Keep on tapping, and *poof*, you’ve got the developer settings options.
                                                   v.     You can notice the Developer Options on your screen now.

b.     Switch On USB Debugging
                                                    i.     Go to the Developer Options.
                                                   ii.     Tick the USB Debugging check box.
                                                  iii.     It may display the Pop Up message, if Yes simply click OK.
                                                  iv.     And it’s done, you can see the USB Debugging is ON now.

c.      confirm your device is connected or not to your computer
                                                    i.     connect your device with USB cable
                                                   ii.     open command prompt
                                                  iii.     type adb devices on cmd prompt
                                                  iv.     your device should list

6.      Create Project in Eclipse:

a.      Create Maven Project
                                                    i.     By clicking new, go to other option
                                                   ii.     Select maven project
                                                  iii.     Provide artifact id and group id
                                                  iv.     Create Maven project

b.     Add Appium dependency in pom.xml file
                                                    i.     Open pom.xml file
                                                   ii.     Go to dependencies
                                                  iii.     Add below Appium dependency
         
      <dependency>
               <groupId>io.appium</groupId>
               <artifactId>java-client</artifactId>
               <version>7.0.0</version>
      </dependency>

      <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.9.13.6</version>
      </dependency>

7.      Add test script
a.      Create new TestNg class
b.      Add below code:
public class BaseTest 
{
              
               public static AppiumDriver<MobileElement> driver;
               @BeforeTest
               public void setup() throws MalformedURLException, InterruptedException
               {
                   DesiredCapabilities cap=new DesiredCapabilities();

                                     cap.setCapability("deviceName", "emulator-5554"); //your device name from adb devices

                                     cap.setCapability("udid", "emulator-5554");//your udid from adb devices

                                     cap.setCapability("appActivity", "com.android.calculator2.Calculator");

                                     cap.setCapability("appPackage", "com.google.android.calculator");

                                     cap.setCapability("platformName", "Android");

                                     cap.setCapability("platformVersion", "R"); //your device platform version

                                   driver=new AppiumDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), cap);

                                   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

                                    Thread.sleep(5000);

} }


Now your script should run on your device. Basically, it opens the calculator app

   

No comments:

Post a Comment

If any suggestions or issue, please provide