iOS and Android Automation Practice

Summary: App: Netease Kan Game (Xone) Tool: appium 1.0 Appium 1.0 has undergone major changes compared to previous versions. 1. Change the xpath path Before: /window[1]/navigationBar[1]/button[4] Current: //UIAApplication[1

App: Netease Game (Xone)
  tool: appium 1.0
  Appium 1.0 is compared with previous versions big change.
  1. Change the xpath path
  Before: /window[1]/navigationBar[1]/button[4]
  Current: //UIAApplication[1]/UIAWindow[1]/UIANavigationBar[1]/UIAButton[4]
  2.Capability parameter name Change
Before:
desiredCapabilities.setCapability(CapabilityType.PLATFORM, "iOS");
desiredCapabilities.setCapability(CapabilityType.VERSION, "7.0");
Current:
desiredCapabilities.setCapability("platformVersion", "7.0");desiredCapabilities.setCapability("platformName ", "iOS");
  3. Appium client UI changes (provide richer parameter options)
  4. Stability is provided, and the client has not crashed.
  Wait,
  let ’s briefly talk about the specific practice process
  1. Project structure, as shown in

  page: get UI element class
  test: use case class, that is, test class
  util: encapsulate most of the public methods
  assertion: assertion class Based
  on the testng framework, ant compiles and executes, and realizes the daily build and run.
2. Code, paste the code of the pass login module for reference
  Test class: PassportLogin
public class PassportLogin extends BaseTest {
private static Logger log = Logger.getLogger(PassportLogin.class);
@DataProvider(name = "passportLoginData")
public static Object [][] passportLoginData() {
return new Object[][] {
{ "Login with the correct NetEase passport", "[email protected]", "xxxxx", "" },
{ "Login with the NetEase passport of a non-NetEase account ", "[email protected]", "xxxx", "
{ "Login with Netease Pass, wrong password", "[email protected]", "xxx",
"Username or password is wrong" },
{ "Do not enter account and password", "", "", "Username cannot be Empty" },
{ "Do not enter password", "[email protected]", "", "Password cannot be empty" },
{ "Do not enter account number", "", "xxxx", "Username cannot be Empty" },
{ "Wrong NetEase Pass Login", MyRandom.getRandomString(10) + "@163.com",
MyRandom.getRandomString(6), "Incorrect username or password" } };
}
@BeforeClass
public void setUp () {
driver = new Orange();
mainPage = new MainPage(driver);
account = new Account(driver);
as = new AssertSettings(driver);
usPage = new UserSettingsPage(driver);
homePage = new HomePage(driver);
mainPage.enterMainPage();
mainPage.enterLogin();
account.logoutTrue();
}
@AfterClass
public void tearDown() {
driver.quit();
}
@AfterMethod
public void end() throws InterruptedException {
log.info("-------------------------------------------------------------------");
}
@Test(dataProvider = "passportLoginData")
public void passportLoginTest(String testName, String passport,
String password, String errorCode) throws InterruptedException {
log.info("测试内容:" + testName);
mainPage.enterLogin();
account.login(passport, password);
if (errorCode != "") {
boolean b = as.assertLogin(errorCode);
driver.sleep(3000);
mainPage.flickToRight();
mainPage.closePage();
Assert.assertTrue(b);
} else {
mainPage.enterLogin();
homePage.settingsClick();
usPage.passportClick();
account.logout();
}
}
}
Since multiple pages are involved, only some Page classes are posted here , such as Account class, used to get login operation
public class Account extends BasePage {
/**
* @Title: Account
* @Description: TODO
* @param @param driver
* @throws
*/
public Account(Orange driver) {
super(driver );
// TODO Auto-generated constructor stub
}
/**
* @Title: login
* @Description: TODO
* @param @param driver
* @return void
* @throws
*/
public void login() {
driver.clickOnElement(By.name("网易通行证登录"));
driver.sendKeys(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]"),
PropertiesHandle.readValue("passport_2"));
driver.sendKeys(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]"),
PropertiesHandle.readValue("password"));
driver.clickOnElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[1]"));
}
/**
* @Title: login
* @Description:TODO
* @param @param driver
* @param @param passport
* @param @param password
* @return void
* @throws
*/
public void login(String passport, String password) {
driver.clickOnElement(By.name("网易通行证登录"));
driver.sendKeys(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]"), passport);
driver.sendKeys(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]"), password);
driver.clickOnElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[1]"));
}
/**
* @Title: login
* @Description: TODO
* @param @param type
* @param @param passport
* @param @param password
* @return void
* @throws
*/
public void login(String type, String passport, String password) {
driver.clickOnElement(By.name(type));
driver.sendKeys(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]"), passport);
driver.sendKeys(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]"), password);
driver.clickOnElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[1]"));
}
/**
* @Title: login
* @Description: TODO
* @param @param type
* @return void
* @throws
*/
public void login(String type) {
driver.clickOnElement(By.name(type));
}
/**
* @Title: logout
* @Description: TODO
* @param @param driver
* @return void
* @throws
*/
public void logout() {
driver.clickOnElement(By.name("Exit the current account"));
driver.clickOnElement(By.name("OK"));
}
}
  The main public class: Orange, which mainly draws on the methods already encapsulated by Kong Qingyun, And make some improvements and use it directly, which is convenient and quick.
  At present, Appium has reached version 1.1. This automation tool is still good. It has good cross-platform and cross-language support, and its stability is gradually improving.


For the latest content, please refer to the author's GitHub page: http://qaseven.github.io/
If you find any content suspected of plagiarism in this community, please send an email to: [email protected] to report and provide relevant evidence , once verified, this community will immediately delete the allegedly infringing content.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326288373&siteId=291194637