Create a gist now

Instantly share code, notes, and snippets.

@Wal-Ramiz /SearchGuide.java Secret
Last active Sep 12, 2017

What would you like to do?
package testProject;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidKeyCode;
import io.appium.*;
import org.openqa.selenium.android.*;
public class SearchGuide {
AndroidDriver driver;
@BeforeClass
public void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("VERSION", "5.1.1");
capabilities.setCapability("deviceName","0815f832cc183305");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("unicodeKeyboard","true");
capabilities.setCapability("resetKeyboard","true");
capabilities.setCapability("appPackage", "com.app.testapplication");
// This package name of your app (you can get it from apk info app)
capabilities.setCapability("appActivity","com.app.testapplication.activity.auth.SplashActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"), capabilities);
}
@Test
public void app() throws Exception {
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
driver.findElement(By.id("com.app.testapplication:id/editTextEmail")).sendKeys("mbasit@gmail.com");
WebElement input = driver.findElement(By.id("com.app.testapplication:id/editTextPassword"));
input.sendKeys("1234567");
//input.sendKeys(Keys.DONE);
//input.back();
//input.pressKeyCode(66);
driver.findElement(By.id("com.app.testapplication:id/buttonSignIn")).click();
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
driver.findElement(By.id("com.app.advanceautoparts:id/search_bar")).sendKeys("guide");
driver.pressKeyCode(66);
//((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.KEYCODE_SEARCH);
//driver.sendKeyEvent(66);
//driver.sendKeys(Keys.ENTER);
//Actions action=new Actions(driver);
//action.sendKeys("Guide").sendKeys(Keys.ENTER).build().perform();
//((AndroidDriver) driver).sendKeyEvent(AndroidKeyCode.ENTER);
//action.(AndroidKeyCode.KEYCODE_SEARCH).build().perform();
}
@AfterClass
public void teardown(){
//close the app
driver.findElement(By.name("Logout")).click();
driver.quit();
}
}

corrected code:

package com.xxxx.tests;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidKeyCode;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;


/**
 * Created by Aleksei on 12/09/2017.
 */
public class test {


    AndroidDriver driver;

    @BeforeClass
    public void setUp() throws MalformedURLException{
        //Set up desired capabilities and pass the Android app-activity and app-package to Appium
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("VERSION", "5.1.1");
        capabilities.setCapability("deviceName","0815f832cc183305");
        capabilities.setCapability("platformName","Android");
        capabilities.setCapability("unicodeKeyboard","true");
        capabilities.setCapability("resetKeyboard","true");



        capabilities.setCapability("appPackage", "com.app.testapplication");
// This package name of your app (you can get it from apk info app)
        capabilities.setCapability("appActivity","com.app.testapplication.activity.auth.SplashActivity");
        driver = new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"), capabilities);
    }

    @Test
    public void app() throws Exception {
        driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
        driver.findElement(By.id("com.app.testapplication:id/editTextEmail")).sendKeys("mbasit@gmail.com");
        WebElement input = driver.findElement(By.id("com.app.testapplication:id/editTextPassword"));
        input.sendKeys("1234567");
        input.sendKeys(Keys.END);
        //input.back();
        //input.pressKeyCode(66);
        driver.findElement(By.id("com.app.testapplication:id/buttonSignIn")).click();
        driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
        driver.findElement(By.id("com.app.advanceautoparts:id/search_bar")).sendKeys("guide");
        driver.pressKeyCode(66);
        driver.pressKeyCode(AndroidKeyCode.KEYCODE_SEARCH);	
        driver.getKeyboard().sendKeys(Keys.ENTER);


    }
    @AfterClass
    public void teardown(){
        //close the app
        driver.findElement(By.name("Logout")).click();
        driver.quit();

    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment