You can use eclipse or android-studio to create java project.
To do this in Linux/ubuntu follow setps:
Download Android SDK and store it in any specific dir.
To open bashrc file to set env variables:
vi ~/.bashrc
In bashrc file save below & use source command to update:
export ANDROID_HOME=/home/praveen/Android/Sdk
export PATH=$JAVA_HOME/bin:$ANDROID_HOME/build-tools/29.0.3:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH
Now save the bashrc file using "source ~/.bashrc"
if you run "which aapt" we should see full path of aapt tool,this will confirm our android sdk evt variables are set correctly.
Download eclipse, create new java project.
download selenium standalone jar, download all selenium java jars & download appium java client jar & add all these as external jars using build-path for project into "class-path" which is very important.
program:
package androidapptest;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
public class testapp {
public static void main(String[] args) {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Mi A2");
caps.setCapability("udid", "4da520f"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "10");
caps.setCapability("appPackage", "com.android.vending");
caps.setCapability("appActivity", "com.google.android.finsky.activities.MainActivity");
caps.setCapability("noReset", "true");
try {
AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
}
}
Now start appium server by double clicking "Appium-linux-1.15.1.AppImage" file to see Appium popup, select Advanced, just click on Start server button to start command line logging of whats happening.
Now in command line, do "adb devices" to get device udid, which we will pass in above program for "udid" field.
Select any app which you want to launch on your connected mobile & sttart your automation, follow as is:
adb shell
<now you will be into adb shell interface>
Run "dumpsys window|grep mCurrentFocus" to fetch clas sname of app & main activityname of app to pass in above program for "appActivity" & "appPackage" fields.
Now execute your java project & see google play store will open on your mobile screen, make sure your screen is ON, from now you can continue automating with any elements using ui automator app to fetch xpaths of each elements from your phone app.
To do this in Linux/ubuntu follow setps:
Download Android SDK and store it in any specific dir.
To open bashrc file to set env variables:
vi ~/.bashrc
In bashrc file save below & use source command to update:
export ANDROID_HOME=/home/praveen/Android/Sdk
export PATH=$JAVA_HOME/bin:$ANDROID_HOME/build-tools/29.0.3:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH
Now save the bashrc file using "source ~/.bashrc"
if you run "which aapt" we should see full path of aapt tool,this will confirm our android sdk evt variables are set correctly.
Download eclipse, create new java project.
download selenium standalone jar, download all selenium java jars & download appium java client jar & add all these as external jars using build-path for project into "class-path" which is very important.
program:
package androidapptest;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
public class testapp {
public static void main(String[] args) {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Mi A2");
caps.setCapability("udid", "4da520f"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "10");
caps.setCapability("appPackage", "com.android.vending");
caps.setCapability("appActivity", "com.google.android.finsky.activities.MainActivity");
caps.setCapability("noReset", "true");
try {
AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
}
}
Now start appium server by double clicking "Appium-linux-1.15.1.AppImage" file to see Appium popup, select Advanced, just click on Start server button to start command line logging of whats happening.
Now in command line, do "adb devices" to get device udid, which we will pass in above program for "udid" field.
Select any app which you want to launch on your connected mobile & sttart your automation, follow as is:
adb shell
<now you will be into adb shell interface>
Run "dumpsys window|grep mCurrentFocus" to fetch clas sname of app & main activityname of app to pass in above program for "appActivity" & "appPackage" fields.
Now execute your java project & see google play store will open on your mobile screen, make sure your screen is ON, from now you can continue automating with any elements using ui automator app to fetch xpaths of each elements from your phone app.
Comments
Post a Comment