Reputation: 45
Hi am very new in appium , I have run my first test case (Java with TestNG) using eclipse but now i want switch to Android Studio. Please provide me step by step process to add jar's and other things into Android Studio
Upvotes: 2
Views: 3618
Reputation: 1
I did all the steps but I rebuild wasn't successful, then I got this as a solution: the android {...} closure in the build.gradle for your app module to resolve the issue:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
and all the errors are solved. my java version was 10 and it didn't work!!
Upvotes: 0
Reputation: 41
Android Studio 3.1.2, Min SDK 21. If Min SDK lower, you can try using a lower version of appium java-client.
Add Java client Jar through gradle in the your gradle build file dependencies section. Make sure that the client version you pick is usable for your minimum/target android SDKs.
dependencies {
testImplementation 'io.appium:java-client:4.1.2'
}
Your android project has a java folder for your source files. Search for a folder that has the word (test) in parentheses. Create a java file in there. If you place it in the (androidTest) folder, you will run into various problems.
Add your unit test code to that file. In my case I was using JUnit.
Install appium server through your preferred means. You can find install executables through https://github.com/appium/appium-desktop/releases/ or you can dabble with nodejs and its package manager.
Configure appium server's settings to match those of your unit test (i.e the ports should match).
Start appium server.
Right click on your test and click the Run 'XXXXX' where XXXXX is the name of your class.
Select the emulator/physical device you desire.
There is no need to manually download jars and add them as I was seeing in some tutorials. If you follow the steps above, you'll have what you need.
Upvotes: 1
Reputation: 1387
You need for Appium setup in Android Studio -
Appium Server
Appium Java Client jar
Selenium client jars
You can view this Video Step By Step Appium Setup with Android Studio
Regards,
Anuja
Upvotes: 1
Reputation: 98
I recommend you to use IntelliJ IDEA. You can create project with gradle where you can insert dependencies, but you can include easly .jars by File -> Project structure -> Libraries -> (+) -> Java and then select your .jar file.
IntelliJ IDEA got testNG already installed so you don't have to install it.
For testing all you need are gson-2.2.2, java-client-4.0.0, selenium-java-2.53.1 jars.
To connect with your device use class
public class Setup {
private final String DEVICE_NAME = "deviceName";
private final String PLATFORM_NAME = "platformName";
private final String PLATFORM_VERSION = "platformVersion";
private final String APP_PACKAGE = "appPackage";
private final String APP_ACTIVITY = "appActivity";
private String deviceName = "Android SDK built for x86"; //device name can be found in device settings
private String platformName = "Android";
private String platformVersion = "6.0"; //version of your android
private String port = "4723"; //port from Appium server
private String url;
private String getIp() throws UnknownHostException {
InetAddress ip = InetAddress.getLocalHost();
return ip.getHostAddress();
}
public AndroidDriver establishConnection() throws MalformedURLException {
try {
url = String.format("http://%s:%s/wd/hub", getIp(), port);
} catch (UnknownHostException e) {
e.printStackTrace();
}
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability(DEVICE_NAME, deviceName);
capability.setCapability(PLATFORM_NAME, platformName);
capability.setCapability(PLATFORM_VERSION, platformVersion);
capability.setCapability(APP_PACKAGE, "my.app.package");
capability.setCapability(APP_ACTIVITY, "my.app.activity");
return new AndroidDriver(new URL(url), capability);
}
}
After this you can create new class with @BeforeClass
where you can create object of Setup class, call establishConnection();
and initialize driver and test your app UI with @Test
methods. Don't forget to install .apk first on your device :)
Upvotes: 2