Q) What is Desired Capability?
A) Desired capabilities: is a class from selenium.
- Desired capabilities is a class that takes the information in JSON structure and sends the
information to the Appium server.
===============================
Q) How to add .apk to the project so that no need to change the build path every time.
A) We will create a folder and store our app in that and call it using the file.
Code is:
File f = new File(“Folder name where you have stored your app let's say App build”);
File fs = new File(fs,”location of the apk”);
Now how to set in desired capability.
Caps.setCapability(MobileCapabilityType.App, fs.getAbsolutePath);
===================================
Q) Connection to appium server.
A) AndroidDriver<AndroidElement> driver = new
AndroidDriver<AndroidElement>(connectionToServer,capabilities);
Where
connectionToServer : (new URL(“http://0.0.0.0/wd/hub”), caps)
For URL import java.net only.
&
Capabilities: caps
Wd stands for WebDriver & hub is used to transfer data.
===================================
Q) What is connection and session in appium.
Session takes 60 sec to close
Close the connection and start again.
===================================
Q) Ways to find elements
A) driver.findElementByXPath("//android.widget.TextView[@text='Preference']");
driver.findElementByXPath("//android.widget.TextView[@text='3. Preference
dependencies']");
driver.findElementById("android:id/checkbox").click();
driver.findElementByXPath("(//android.widget.RelativeLayout)[2]").click();
Using get():
driver.findElementsByClassName("android.widget.Button").get(1).click();
Using UIAutomator:
//driver.findElementByAndroidUIAutomator("attribute("value")");
driver.findElementByAndroidUIAutomator("text(\"Views\")").click();
Using properties e.g. clickable
int a = driver.findElementsByAndroidUIAutomator("new UiSelector().clickable(true)").size();
===================================
Q) Scroll in Appium
A)
driver.findElementByAndroidUIAutomator("new UiScrollable(new
UiSelector()).scrollIntoView(text(\"Radio Group\"));");
("new UiScrollable(new UiSelector()) :- This is Android methods not Appium
===================================
Q) How to get current activity or the current page details
A) getActivity() method is used
system.out.println(driver.getActivity());
Output in console will be : .ApiDemos
===================================
Q) How to get What type of app you are working on?
A) getContext() method is user.
system.out.println(driver.getContext());
Output in console will be : “NATIVE_APP”
===================================
Q) How to get current orientation details of mobile?
A) driver.getOrientation();
system.out.println(driver.getOrientation());
===================================
Q) Check wether mobile is locked or not?
A) driver.islocked();
===================================
Q) How to hide keyboard?
A) driver.hideKeyboard();
===================================
Q) How to click on home button or back button of mobile device?
A) driver.pressKeyCode(AndroidKeyCode.Action_Home)
Action_Back;
etc.
===================================
Q) Perform click on Toggle button
A)
Point point=
driver.findElementById("com.raaga.android:id/toggle_notifyrecommend").getLocation();
TouchAction t= new TouchAction(driver);
//toggle on
t.tap(point.x+20, point.y+30).perform();
//toggle off
t.tap(point.x+100, point.y+30).perform();
===================================
Q) How to execute the scripts without changing the device type i.e. emulator or real device.
A) Do below changes in TestBase.java File.
TestBase.java
Public static AndroidDriver<AndroidElement> capabilities(String device) throw malformed
exception
Public void setup()
{
AndroidDriver<AndroidElement> driver;
DesiredCapabilities caps = new DesiredCapabilities();
if(device.equals(“real”))
{
caps.setCapability(MobileCapabilityType.DEVICE_NAME,”Real
Device”);
}
else if(device.equals(“emulator”))
{
caps.setCapability(MobileCapabilityType.DEVICE_NAME,”emalutor
Device”);
}
}
And add below code in your class where you are calling your desired capabilities.
AndroidDriver<AndroidElement> driver = setup(“Device type”);
Under device type mention device you want to use i.e. emulator or real.
setup(“emulator”);
setup(“real”);
===================================
Q) How to scroll down in Real device.
A)
Dimension size = this.driver.manage() .window().getSize ();
int startX = size.getWidth () / 2;
int startY = size.getHeight () / 2;
int endX = 0;
int endY = (int) (startY * -1 * 0.5);
driver.swipe(startX, startY,endX,endY,2000);
driver.findElementByAndroidUiAutomator(“new UiScrollable().scrollIntoView(\”WebViews\”)”);
0 Comments