Appium: Automation Testing Script for Android Calculator

using NUnit.Framework;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using System.Collections.Generic;
using System.Diagnostics;

namespace AndroidTesting
{
    [TestFixture()]
    public class Test
    {
        AppiumDriver<AppiumWebElement> driver;

        [SetUp]
        public void TestSetUp() 
        {
            

            DesiredCapabilities capabilities = new DesiredCapabilities();

            capabilities.SetCapability(deviceName1);
            capabilities.SetCapability(platformVersion4.4.2);
            capabilities.SetCapability(platformNameAndroid);

            capabilities.SetCapability(appPackagecom.android.calculator2);
            capabilities.SetCapability(appActivityCalculator);

            driver = new AndroidDriver<AppiumWebElement>(new Uri(http://localhost:4723/wd/hub), capabilities);

        }

    [TearDown]
        public void TestCleanUp()
        {
            
        }

        [Test()]
        public void TestCalculator()
        {
            driver.FindElement(By.Id(com.android.calculator2:id/digit1)).Click();
            driver.FindElement(By.Id(com.android.calculator2:id/plus)).Click();
            driver.FindElement(By.Id(com.android.calculator2:id/digit1)).Click();
            driver.FindElement(By.Id(com.android.calculator2:id/equal)).Click();

            if (driver.FindElement(By.ClassName(android.widget.EditText)).Text == 2)
            {
                Console.WriteLine(Calculator successfully works!);
            }
        }
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s