пакет com.testng.learn;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidKeyCode;
открытый класс First {
AndroidDriver driver;<br/>
DesiredCapabilities caps;<br/>
@BeforeTest<br/>
public void DC() {<br/>
try {<br/>
// Set the Desired Capabilities<br/>
caps = new DesiredCapabilities();<br/>
caps.setCapability("deviceName", "My Phone");<br/>
caps.setCapability("udid", "LGM70021d764e8"); // Give Device ID of your mobile phone<br/>
caps.setCapability("platformName", "Android");<br/>
caps.setCapability("platformVersion", "7.1.1");<br/>
caps.setCapability("appPackage", "com.android.contacts");<br/>
caps.setCapability("appActivity", "com.android.contacts.activities.DialtactsActivity");<br/>
caps.setCapability("noReset", "true");<br/>
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);<br/>
} catch (MalformedURLException e) {<br/>
// TODO Auto-generated catch block<br/>
e.printStackTrace();<br/>
}
}
@DataProvider()<br/>
public void scroll(String text) {<br/>
try {<br/>
System.out.println(text);<br/>
driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector()).scrollIntoView(" + "new UiSelector().text(\"" + text + "\"));"))
.click();<br/>
Thread.sleep(5000);<br/>
} catch (InterruptedException e) {<br/>
// TODO Auto-generated catch block<br/>
e.printStackTrace();<br/>
}<br/>
}<br/>
@Test(priority = 0)<br/>
public void print() {<br/>
try {<br/>
String text = "Karthik";<br/>
Thread.sleep(2000);<br/>
driver.findElementByAccessibilityId("Contacts Tab 3 of 4").click();<br/>
Thread.sleep(1000);<br/>
First f1 = new First();<br/>
f1.scroll(text);<br/>
Thread.sleep(1000);<br/>
driver.pressKeyCode(AndroidKeyCode.BACK);<br/>
Thread.sleep(2000);<br/>
driver.pressKeyCode(AndroidKeyCode.HOME);<br/>
} catch (InterruptedException e) {<br/>
// TODO Auto-generated catch block<br/>
e.printStackTrace();<br/>
}<br/>
}<br/>
}