mercredi 19 avril 2017

How to record a test cases for android in Appium Desktop?

I have successfully installed Appium on my macOs Sierra along with all the necessary tools to run it and I wanted to start recording test cases for android.

I have followed this tutorial to do so:

http://ift.tt/2hzP3mZ

I have installed

  • the desktop version of Appium
  • Appium Jar files for Java
  • Appium Client Library

and I already had Android studio and Java pre-installed.

What I want to do, is to record a test case for android in Appium. But I cannot figure out how can I do so. When I run Appium, I first have to start the server, and I am doing so by entering 127.0.0.1 for the host and Port 4723.

After that, I start the session and everything starts normally but I cannot find the record button: No record button

And this is the written test case from Android studio (which when I run it, it gives me some errors).

package com.example.hermes.doritest;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.*;
import org.openqa.selenium.WebDriver;
import org.junit.Test;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import io.appium.java_client.remote.MobileCapabilityType;



public class ApiumTest {

    WebDriver driver;

    public ApiumTest() { }

    @Before
    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(MobileCapabilityType.PLATFORM_NAME,"Android");

        // Set BROWSER_NAME desired capability. It's Android in our case here.
        //capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION,"7.1.1");

        // Set android VERSION desired capability. Set your mobile device's OS version.
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"emulator-5554");

        // 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", "com.android.calculator2");

        // 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", "com.android.calculator2.Calculator");

        // 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://ift.tt/1eWSHgW"), capabilities);
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);


    }

    @Test
    public void testFirstCalculator() {


        // Click on DELETE/CLR button to clear result text box before running test.
        driver.findElements(By.xpath("//android.widget.Button")).get(0).click();

        // Click on number 2 button.
        driver.findElement(By.name("7")).click();

        driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
    }

    @After
    public void End() {
        driver.quit();
    }

And I cannot find out how can I record a test case for android in Appium.

Aucun commentaire:

Enregistrer un commentaire