Appium
Appium
https://naveenautomationlabs.com/tag/appium/
https://naveenautomationlabs.com/appium-tutorials/
https://naveenautomationlabs.com/12-executing-test-case-in-appium-with-pom/
interview Q:
https://www.guru99.com/appium-interview-questions.html
Appium Architecture :
http://www.automationtestinghub.com/appium-tutorial/
https://www.edureka.co/blog/appium-architecture/
http://study-automation.blogspot.com/2017/08/appium-architecture-how-appium-works.html
http://www.automationtestinghub.com/first-appium-test-script/
MAC OS – 10.15.5
http://www.automationtestinghub.com/apppackage-and-appactivity-name/
appPackage:
In very basic terms, appPackage is the technical name of the app which is provided by its developers. It’s
actually a top level package under which all the code for the app resides.
- Connect device to system- adb devices- unlock app and open app-
http://www.automationtestinghub.com/appium-tutorial/
adb devices
example:
$ adb devices
List of devices attached
5856423841563398 device
emulator-5554 device
To specify the device when using logcat
https://appiumpro.com/editions/tag/All%20Devices
Desiredcap: http://appium.io/docs/en/writing-running-appium/caps/
1 package tests;
3 import java.net.MalformedURLException;
4 import java.net.URL;
6 import org.openqa.selenium.remote.DesiredCapabilities;
7 import io.appium.java_client.AppiumDriver;
8 import io.appium.java_client.MobileElement;
9 import io.appium.java_client.android.AndroidDriver;
10
13
//Set the Desired Capabilities
14
DesiredCapabilities caps = new DesiredCapabilities();
15
caps.setCapability("deviceName", "My Phone");
16
caps.setCapability("udid", "ENUL6303030010"); //Give Device ID of your mobile
17
phone
18
caps.setCapability("platformName", "Android");
19
caps.setCapability("platformVersion", "6.0");
20
caps.setCapability("appPackage", "com.android.vending");
21
caps.setCapability("appActivity",
22
"com.google.android.finsky.activities.MainActivity");
23
caps.setCapability("noReset", "true");
24
25
//Instantiate Appium Driver
26
try {
27
AppiumDriver<MobileElement> driver = new
28
AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
29
30
} catch (MalformedURLException e) {
31
System.out.println(e.getMessage());
32
}
33
}
34
https://appiumpro.com/editions/41-how-to-test-real-ios-devices-with-appium-part-2
import io.appium.java_client.ios.IOSDriver;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
@Before
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new
DesiredCapabilities();
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "12.0.1");
capabilities.setCapability("deviceName", "iPhone 8");
capabilities.setCapability("udid", "auto");
capabilities.setCapability("bundleId", "<your bundle
id>");
capabilities.setCapability("xcodeOrgId", "<your org
id>");
capabilities.setCapability("xcodeSigningId", "iPhone
Developer");
capabilities.setCapability("updatedWDABundleId", "<bundle
id in scope of provisioning profile>");
@After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
@Test
public void testFindingAnElement() {
driver.findElementByAccessibilityId("Login Screen");
}
}
Identifying elements in Automatoriviewer: http://www.automationtestinghub.com/uiautomatorviewer-
inspect-elements/
2 driver.findElement(By.id("com.android.vending:id/search_box_idle_text")).click();
3 //OR
4 driver.findElementById("com.android.vending:id/search_box_idle_text").click();
7 driver.findElementByAccessibilityId("Search").click();
5 if(element.getAttribute("contentDescription").equals("Search")) {
6 element.click();
7 break;
8 }
}
Swipe :
https://mahantesh-hadimani.blogspot.com/2019/08/how-to-swipe-up-or-scroll-up-in-appium.html
https://www.nextgenerationautomation.com/post/appium-interview-questions-answers
IOS Logs :
Using Xcode
1. First, install Xcode on your mac machine. Next, launch Xcode.
2. Connect your iOS device to the Mac through USB.
3. Launch Xcode. Go to Windows > Devices and Simulators.
4. Reproduce the problem you encountered.
5. Choose your device from the devices section on the left side of
the screen.
6. Click on the up-triangle on the bottom of the screen to view
device logs.
7. Click on the down arrow on the bottom right of the screen to
save the device logs as a file.
8. Select View Device Logs button under the Device
Information section on the right-hand panel to view crash logs.
9. Under Process column on the left, identify and select your app
and click on Crash Log to see the contents.
10. Right click the corresponding app entry on the Process
Column and click on Export Log to save the crash log.
https://www.browserstack.com/guide/appium-ios-tutorial
https://techapple.net/2015/01/4-waysmethods-install-ipa-file-app-iphone-ipad-ipod-online-
offline-methods/
Touch actions :
https://appium.io/docs/en/writing-running-appium/touch-actions/
Multi touch :
action0 = TouchAction().tap(el)
action1 = TouchAction().tap(el)
MultiAction().add(action0).add(action1).perform()
TouchAction().press(el0).moveTo(el1).release()
Scrolling
To allow access to this special feature, we override
the execute or executeScript methods in the driver, and prefix the command
with mobile:. See examples below:
To scroll, pass direction in which you intend to scroll as parameter.
Swiping
This is an XCUITest driver specific method that is similar to scrolling (for
reference, see https://developer.apple.com/reference/xctest/xcuielement).
This method has the same API as Scrolling, just replace "mobile: scroll" with
"mobile: swipe"
@AndroidFindBy(id = "username")
AndroidElement loc_Username_android;
@iOSXCUITFindBy(accessibility = "username")
AndroidElement loc_Username_ios;
public class OS {
public static AppiumDriver<?> driver;
@BeforeMethod
public static void startTest(String platform) {
if(platform.equalsIgnoreCase("Android")) {
driver = startAppium_Android();
} else {
driver = startAppium_IOS();
}
}
/*
* This method is used for initiate the AppiumDriver with caps and connection
protocol
*/
public static AndroidDriver<?> startAppium_Android() {
// Initializing the Appium driver
try {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME,
"Android");
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9");
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "5642c6b9");
cap.setCapability("appActivity",
"com.invoiceapp.InvoiceLaunchScreenAct");
cap.setCapability("appPackage", "com.invoiceapp");
cap.setCapability("autoLaunch", false);
cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT,
500);
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME,
AutomationName.ANDROID_UIAUTOMATOR2);
// driver is declared as an AndroidDriver, which supports AndroidElements
driver = new AndroidDriver<AndroidElement>(new
URL("http://127.0.0.1:4723/wd/hub"), cap);
} catch (Exception e) {
e.printStackTrace();
}
//Returning the instance of the driver to the parent method
return (AndroidDriver<?>) driver;
}
/*
* This method is used for initiate the IOSDriver with caps and connection
protocol
*/
public static IOSDriver<?> startAppium_IOS() {
// Initializing the Appium driver
try {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION,
"12.0.1");
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 8");
cap.setCapability(MobileCapabilityType.UDID,
"3jtn3j4n3ijn3ji4nrj34inrj34nr34nrk");
cap.setCapability("bundleId", "com.invoiceapp");
cap.setCapability("autoLaunch", false);
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME,
AutomationName.IOS_XCUI_TEST);
// driver is declared as an IOSDriver, which supports IOSElements
driver = new IOSDriver<IOSElement>(new
URL("http://127.0.0.1:4723/wd/hub"), cap);
} catch (Exception e) {
e.printStackTrace();
}
//Returning the instance of the driver to the parent method
return (IOSDriver<?>) driver;
}
}
Question: Write a method to wait for specific element to vanish on
mobile app before certain interval?
Answer:
public boolean
waitForElementToVanish(AppiumDr
iver driver, MobileElement
element, int maxWait) {
try {
int i = 0;
while(element.isDisplayed() &&
i<3) {
Thread.sleep(maxWait);
i++;
}
return !element.isDisplayed();
}
catch (InterruptedException e) {
e.printStackTrace();
}
return false;
}