Appium


Introduction to Appium


Appium is an open-source tool for automating native, mobile web, and hybrid applications on iOS mobile, Android mobile, and Windows desktop platforms. Native apps are those written using the iOS, Android, or Windows SDKs. Mobile web apps are web apps accessed using a mobile browser (Appium supports Safari on iOS and Chrome or the built-in 'Browser' app on Android). Hybrid apps have a wrapper around a "webview" -- a native control that enables interaction with web content.

Appium Philosophy

  • Appium was designed to meet mobile automation needs according to a philosophy outlined by the following four tenets:
  • You shouldn't have to recompile your app or modify it in any way in order to automate it.
  • You shouldn't be locked into a specific language or framework to write and run your tests.
  • A mobile automation framework shouldn't reinvent the wheel when it comes to automation APIs.
  • A mobile automation framework should be open source, in spirit and practice as well as in name!

Setup Selenium GRID to execute Appium script on IOS Simulator


Machine 1 : Windows OS (will be acting as a HUB)
Machine 2 : MAC OS (Will be acting as a node)

Follow steps mentioned below :
Machine 1 Setup (IP Address : 10.10.0.46) (WIndows OS)
1. Download Selenium Standalone server and save it in a folder
2. Open command prompt, navigate to the location where selenium JAR is saved and start Hub using following command
java -jar selenium-server-standalone-3.4.0.jar -role hub -host 10.82.89.95
NOTE : As HUB port is not mentioned in above command, so it will be started on 4444 by default
After executing above command, invoke following URL to check Hub is started or not
http://HUB_IP_Address:hub_port/grid/console
Eg : http://10.82.89.95:4444/grid/console

Machine 2 Setup (IP Address : 10.10.1.40) (MAC OS)

1. Download Selenium Standalone server and save it in a folder.

2. Install Appium and start the server by using below command.
NOTE : Refer this doc to Install Appium via Terminal (see below section)
Here, we are using Appium version 1.9.1
1 appium --port 4723 --address 10.10.1.40
After executing above command, Appium server will get started on port 4723

3. Now is the time to Register a node. Before registering a node to a HUB, first you have to create JSON file and save it in a folder where selenium stand alone jar is saved.
Example: example_1.json
{
  "capabilities": [
  {
      "browserName": "safari",
      "maxInstances": 1,
      "platform":"MAC",
      "seleniumProtocol": "WebDriver",
      "automationName": "XCUITest"
  }
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "url": http:// 10.10.1.40.145:4444/wd/hub,   //IP address of Node
  "host": "10.10.1.40", //node ip
  "port": 4444, //node port
  "maxSession": 5,
  "register": true,
  "registerCycle": 5000,
  "role": "node",
  "hub": http://10.82.89.95:4444, //Hub IP address
  "hubPort": 4444,  //Port number
  "hubHost": "10.82.89.95", //IP address
  "debug": false,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {}
}

4. Open Terminal in MAC OS, navigate to the folder where JSON file is saved and execute following command to register node with Hub Machine
appium --address  10.10.1.40.145--session-override  --full-reset  --nodeconfig example_1.json --port 4444

5. After executing above command, node will get registered to HUB. Just check it by invoking following URL : http://10.82.89.95:4444/grid/console

Grid set up is done. Next step is to execute Appium script on IOS simulator or device from Remote Machine
Below sample code will be executed on IOS Simulator in Machine 2 (MAC OS)

6. Now, execute below code from Machine 1( Windows OS) and it will executed on IOS simulator in Machine 2 (MAC OS)
using NUnit.Framework;
using OpenQA.Selenium.Remote;
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Enums;
using OpenQA.Selenium.Appium.iOS;
using System.Threading;

namespace AppiumGrid
{
    [TestFixture]
    public class IOSBasicInteractionsTest
    {
        IOSDriver<IWebElement> driver;

        [SetUp]
        public void BeforeAll()
        {
            //Desired capabilities of node
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.SetCapability(MobileCapabilityType.BrowserName, "safari");
            capabilities.SetCapability(MobileCapabilityType.PlatformName, "ios");
            capabilities.SetCapability("platform", "MAC");
            capabilities.SetCapability(MobileCapabilityType.PlatformVersion, "10.1");
            capabilities.SetCapability(MobileCapabilityType.AutomationName, "XCUITest");
            capabilities.SetCapability(MobileCapabilityType.DeviceName, "iPhone 7");
            Uri url = new Uri("http://10.82.89.95:4444/wd/hub"); //IP address of hub
            driver = new IOSDriver<IWebElement>(url, capabilities, TimeSpan.FromSeconds(540)); //Intitailze web driver
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
        }

        [Test]
        public void TestShouldSendKetsToInputs()
        {                    
            driver.Url = "http://saucelabs.com/test/guinea-pig";        
            IWebElement idElement = driver.FindElement(By.Id("i_am_an_id"));           
            IWebElement commentElement = driver.FindElement(By.Id("comments"));           
            commentElement.SendKeys("This is an awesome comment");
            IWebElement submitElement = driver.FindElement(By.Id("submit"));
            submitElement.Click();                
            IWebElement yourCommentsElement = driver.FindElement(By.Id("your_comments"));
            Thread.Sleep(2000);
        }

        [TearDown]
        public void AfterAll()
        {
            driver.Quit();
        }
    }
}

That’s it.

Download and Install Appium on MAC OS via Terminal


Before Installing Appium, first you have to install Home Brew software.
Home Brew Installation
Home Brew is a open source software management system that actually simplifies the software installation on MAC Operating system
1.      Launch Terminal and run following command to install Home Brew :
2.       Once Home Brew Installation is completed, next you have to install Appium using following commands:
a.      brew install node // get node.js
b.      brew install carthage        //it is for ios device
c.      brew install libimobiledevice –HEAD  //it is for ios device
d.      npm install -g ios-deploy ( make sure you have Xcode installed first )
e.      brew install ideviceinstaller     //it is for ios device
f.       npm install -g appium // get appium
g.      npm install wd // get appium client
h.      npm install appium-doctor -g //check all required software is installed

3.      After Appium installation, you can easily start Appium Server by just typing appium in terminal
Appium server will be started on default Port which is 4723 
You can also pass parameters while starting Appium server like :
appium --port 4724 --address 10.10.1.40
--port  //Input specific Port number
--address //Input System IP Address

No comments:

Post a Comment