import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import org.openqa.selenium.WebElement;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.RemoteWebDriver;
public class AppiumTest {
public static void main(String[] args) throws MalformedURLException {
// Define the Desired Capabilities
UiAutomator2Options options = new UiAutomator2Options();
options.setPlatformName("Android");
options.setDeviceName("Pixel_4_Emulator"); // Replace with the name of your device/emulator
options.setAutomationName("UiAutomator2");
options.setApp("/path/to/your/app.apk"); // Path to your APK file
// Initialize the AndroidDriver
URL appiumServerUrl = new URL("http://localhost:4723");
RemoteWebDriver driver = new AndroidDriver<>(appiumServerUrl, options);
// Find the username field (replace with the correct element locator)
WebElement usernameField = driver.findElement(AppiumBy.id("com.example:id/username"));
// Input text into the username field
usernameField.sendKeys("testuser");
// Find the password field (replace with the correct element locator)
WebElement passwordField = driver.findElement(AppiumBy.id("com.example:id/password"));
// Input text into the password field
passwordField.sendKeys("password");
// Click the login button again
WebElement loginButton = driver.findElement(AppiumBy.accessibilityId("loginButton"));
loginButton.click();
// Close the driver after test execution
driver.quit();
}
}
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
namespace dotnet_appium.Tests;
public class AppiumTest
{
[Test]
public void TestGestures()
{
var serverUri = new Uri("http://localhost.225:4723");
var options = new AppiumOptions();
options.PlatformName = "Android";
options.AutomationName = "UiAutomator2";
options.DeviceName = "Pixel 7 API 34";
options.PlatformVersion = "14";
options.App = "/path/to/your/app.apk"; // Path to your APK file
options.AddAdditionalAppiumOption("appium:appPackage","com.example.yourapp");
options.AddAdditionalAppiumOption("appium:appActivity", "com.example.yourapp.MainActivity");
AppiumDriver driver = new AndroidDriver(serverUri, options);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(90);
// Find the username field (replace with the correct element locator)
IWebElement usernameField = driver.FindElement(MobileBy.Id("com.example:id/username"));
// Input text into the username field
usernameField.SendKeys("testuser");
// Find the password field (replace with the correct element locator)
IWebElement passwordField = driver.FindElement(MobileBy.Id("com.example:id/password"));
// Input text into the password field
passwordField.SendKeys("password");
// Click the login button again
IWebElement loginButton = driver.FindElement(MobileBy.AccessibilityId("loginButton"));
loginButton.Click();
// Close the driver after test execution
driver.Quit();
}
}
from appium import webdriver
from appium.options.android import UiAutomator2Options
from appium.webdriver.common.appiumby import AppiumBy
options = UiAutomator2Options()
options.platform_name = "Android"
options.platformVersion = '15'
options.device_name = "YourDeviceName"
options.app_activity = ".MainActivity"
options.App = "/path/to/your/app.apk"
driver = webdriver.Remote('http://localhost:4723', options=options)
driver.implicitly_wait(30)
# Find the username field (replace with the correct element locator)
username_field = driver.find_element(AppiumBy.ID, "com.example:id/username")
# Input text into the username field
username_field.send_keys("testuser")
# Find the password field (replace with the correct element locator)
password_field = driver.find_element(AppiumBy.ID, "com.example:id/password")
# Input text into the password field
password_field.send_keys("password")
# Click the login button again
login_button = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "loginButton")
login_button.click()
# Close the driver after test execution
driver.quit()
const { remote } = require('webdriverio');
const capabilities =
{
platformName: 'Android',
'appium:automationName': 'UiAutomator2',
'appium:deviceName': 'Pixel 7 API 34',
'appium:platformVersion':'14',
'app' : '/path/to/my.app',
'appium:appActivity': '.MainActivity',
};
const wdOpts = {
hostname: 'localhost',
port: 4723,
logLevel: 'info',
capabilities,
};
async function runTest()
{
const driver = await remote({capabilities: wdOpts});
try
{
// Find the username field (replace with the correct element locator)
let usernameField = driver.$("#com.example:id/username");
// Input text into the username field
usernameField.setValue("testuser");
// Find the password field (replace with the correct element locator)
let passwordField = driver.$("#com.example:id/password");
// Input text into the password field
passwordField.setValue("password");
// Click the login button again
let loginButton = driver.$("~loginButton");
loginButton.click();
}
catch (error)
{
console.error("Test failed:", error);
}
finally
{
// Pause briefly for visibility and close session
await driver.pause(2000);
await driver.deleteSession();
}
}
import io.appium.java_client.AppiumBy
import io.appium.java_client.android.AndroidDriver
import io.appium.java_client.android.options.UiAutomator2Options
import org.openqa.selenium.remote.RemoteWebDriver
import java.net.URI
import kotlin.test.Test
class AppiumTest {
@Test
fun myFirstTest()
{
// Define the Desired Capabilities
val options = UiAutomator2Options()
options.setPlatformName("Android")
options.setDeviceName("Pixel_4_Emulator") // Replace with the name of your device/emulator
options.setAutomationName("UiAutomator2")
options.setApp("/path/to/your/app.apk") // Path to your APK file
// Initialize the AndroidDriver
val serverUrl = URI.create("http://localhost:4723").toURL()
val driver: RemoteWebDriver = AndroidDriver(serverUrl, options)
// Find the username field (replace with the correct element locator)
val usernameField = driver.findElement(AppiumBy.id("com.example:id/username"))
// Input text into the username field
usernameField.sendKeys("testuser")
// Find the password field (replace with the correct element locator)
val passwordField = driver.findElement(AppiumBy.id("com.example:id/password"))
// Input text into the password field
passwordField.sendKeys("password")
// Click the login button again
val loginButton = driver.findElement(AppiumBy.accessibilityId("loginButton"))
loginButton.click()
// Close the driver after test execution
driver.quit()
}
}