Search code examples
androidandroid-studiotestingautomationappium

how to set environment variable for activate uiautomatorviewer in android using studio


Can anyone here to help me in setting up environment for integrating Appium tool for automation testing. I have stuck at uiautomatorviewer.

I have set up Android Studio and installed JDK too.


Solution

  • Set up Environment Variable:

    1. Android SDK Path: C:\Users\user_name\AppData\Local\Android\Sdk

    2. Set ANDROID_HOME in Environment Variable: and set path of SDK from above

    3. In Android SDK folder, there are three specific folders that you need to add to the Path variable. These folders are –

      C:\Users\user_name\AppData\Local\Android\Sdk\platform-tools C:\Users\user_name\AppData\Local\Android\Sdk\tools C:\Users\user_name\AppData\Local\Android\Sdk\tools\bin

      %ANDROID_HOME%\platform-tools ANDROID_HOME%\tools %ANDROID_HOME%\tools\bin

    4. Set Up PATH variable:

      You should have added all the 3 folder locations as this – ;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;%ANDROID_HOME%\tools\bin

    5. To verify that all the Android Environment Variables are correctly setup, open command prompt and run this command: sdkmanager – -list (please note that there should be no space between the 2 hyphens).

    6. You can also run this command: uiautomatorviewer in command prompt. This will open UI Automator Viewer window.

    7. Set JAVA_HOME in environment variable:

      C:\Program Files\Java\jdk1.8.0_131

    8. Add this variable to PATH variable like below:

      ;%JAVA_HOME%\bin;

    To complete automation setup follow below instructions:

    Use uiautomatorviewer to capture screen.

    Steps for Appium Setup:
    
    1.  Install android studio
    2   SDK
    2.  Appium jar files selenium
    3.  Appium java client jar
    4.  Java selenium library
    5.  Appium server
    6.  Java
    7   install pdanet in both system and mobile device co connectivity
    8   gson jar files
    
    
    
    
    
    **steps**
    Open android Studio
    
    Create new project
    
    Create new basic activity
    
    Copy java client jar file and paste in the app/lib folder
    
    select all jar copied files in the lib folder then right click and click on "Add as library".
    
    select build.gradle then rebuild project
    
    commit jUnit and paste following code beneath of it
    testCompile 'org.assertj:assertj-core:2.0.0'
    testCompile 'org.testng:testng:6.9.10'
    
    sync the code
    
    Right click on Package Name the create a new class
    
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeMethod;
    
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;
    public class WaitTest {
        RemoteWebDriver driver;
    
        @BeforeMethod
        public void setUp() throws MalformedURLException {
            // Created object of DesiredCapabilities class.
            DesiredCapabilities capabilities = new DesiredCapabilities();
    
            // Set android deviceName desired capability. Set your device name.
    
            capabilities.setCapability("deviceName", "4200174ad22b7200");
    
            // Set BROWSER_NAME desired capability. It's Android in our case here.
            capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
    
            // Set android VERSION desired capability. Set your mobile device's OS version.
    
            capabilities.setCapability(CapabilityType.VERSION, "5.1.1");
    
            // Set android platformName desired capability. It's Android in our case here.
            capabilities.setCapability("platformName", "Android");
    
            // Set android appPackage desired capability. It is
            // com.android.calculator2 for calculator application.
            // Set your application's appPackage if you are using any other app.
            capabilities.setCapability("appPackage", "in.dishtv.svctechnician");
    
            // Set android appActivity desired capability. It is
            // com.android.calculator2.Calculator for calculator application.
            // Set your application's appPackage if you are using any other app.
            capabilities.setCapability("appActivity", "in.dishtv.svctechnician.activity.MyActivity");
    
            // Created object of RemoteWebDriver will all set capabilities.
            // Set appium server address and port number in URL string.
            // It will launch calculator app in android device.
            driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
            //driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    
        }
    
        @org.junit.Test
        public void LoginTest1() {
            try {
                setUp();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            driver.findElement(By.id("userNameEdittext")).sendKeys("james");
    
            driver.findElement(By.id("passwordEdittext")).sendKeys("bond");
    
            driver.findElement(By.id("submitButton")).click();
    
    
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        }
    
        @AfterMethod
        public void End() {
            driver.quit();
        }
    }
    
    
    Do not import Selenium jar (because of it's too long size) use Gradle link from Below:
    
    
        **compile group: 'org.seleniumhq.selenium', name: 'selenium-server-standalone', version: '2.53.0'**
    
    
    
    Start Appium server
    
    concect device 
    
    
    run tests in the android studio