To install and set up Appium in Eclipse, follow these steps carefully. This includes setting up all dependencies like Java, Android SDK, Appium server, Node.js, and Eclipse with Maven or TestNG support.
Step-by-Step Guide to Set Up Appium in Eclipse
1. Install Java (JDK)
Download JDK: https://www.oracle.com/java/technologies/javase-downloads.html
Install it and set JAVA_HOME in environment variables:
JAVA_HOME = C:\Program Files\Java\jdk-<version> Path => Add: %JAVA_HOME%\bin
2. Install Node.js
Appium is built on Node.js.
Download: https://nodejs.org/
After installation, verify:
node -v npm -v
3. Install Appium Server
Open Command Prompt and run:
npm install -g appium
Verify:
appium -v
4. Install Eclipse IDE
Download: https://www.eclipse.org/downloads/
Recommended: Eclipse IDE for Java Developers
5. Create a Maven Project in Eclipse
File > New > Project > Maven Project
Use archetype:
maven-archetype-quickstart
Add Appium & Selenium Dependencies
<dependencies> <!-- Selenium --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.20.0</version> </dependency> <!-- Appium Java Client --> <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>9.0.0</version> </dependency> <!-- TestNG (Optional) --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.9.0</version> <scope>test</scope> </dependency> </dependencies>
6. Start Appium Server
Option 1: Use Appium Desktop GUI > Start Server
Option 2: Use CLI:
appium
Sample Appium Test in Eclipse
Sample Code to Launch Calculator in Android Emulator:
Sample Code to Launch Calculator in Android Emulator:
import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.URL; public class AppiumTest { public static void main(String[] args) throws Exception { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11.0"); // your emulator/device version caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); caps.setCapability("appPackage", "com.android.calculator2"); caps.setCapability("appActivity", "com.android.calculator2.Calculator"); AndroidDriver driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), caps); Thread.sleep(5000); driver.quit(); } }
Things to remember:
Emulator is running OR real device is connected with USB debugging ON
Appium server is running
Environment variables are correctly set
No comments:
Post a Comment