我遇到了appium测试组的问题。我为我的应用程序编写了多个测试用例,并且一次运行不同的集合。
基本上,我的测试流程是:使用Google登录=>输入密码=>登出 然后另一个设置与Facebook登录相同的流程。
以下代码是用AppiumTest.java文件编写的
@Test
public class AppiumTest {
IOSDriver<MobileElement> driver = null;
public DesiredCapabilities capabilitiesForDevice(String deviceCode) {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("udid", "SOME_VALID_UDID"); // 7+
capabilities.setCapability("platformVersion", "10.3.3");
capabilities.setCapability("app", "PACKAGE_PATH");
capabilities.setCapability("noReset", false);
capabilities.setCapability("showXcodeLog", true);
capabilities.setCapability("clearSystemFiles", false);
...
return capabilities;
}
@BeforeSuite(groups = {"google"}) // Removing suite also does not make any effect
public void setup() throws MalformedURLException {
System.out.print("Setting up driver.\n");
DesiredCapabilities capabilities = capabilitiesForDevice("iPhone5s");
String url = "http://0.0.0.0:4723/wd/hub";
driver = new IOSDriver<MobileElement>(new URL(url), capabilities);
}
@AfterSuite(groups = {"facebook"})
// Removing suite also does not make any effect
// Between 2 tests execution this method is not being called
public void tearDown() {
System.out.println("AfterSuite ... QUITTING DRIVER...");
driver.quit();
}
public MobileElement getElementByName(String name) {
try {
MobileElement theElement = (MobileElement) (new WebDriverWait(driver, 30))
.until(ExpectedConditions.visibilityOfElementLocated(By.name(name)));
return theElement;
} catch (Exception e) {
// e.printStackTrace();
}
return null;
}
public MobileElement getElementByXPath(String xpath) {
try {
MobileElement theElement = (MobileElement) (new WebDriverWait(driver, 30))
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));
return theElement;
} catch (Exception e) {
// e.printStackTrace();
}
return null;
}
@Test(groups = {"google"}, priority = 1)
public void loginWithGoogle() {
if (driver == null) {
printLog("Test driver is null.");
try {
setup();
} catch (MalformedURLException e) {
// e.printStackTrace();
}
}
printLog("driver = " + driver);
printLog("\nLoading is null and not logged in.." + System.currentTimeMillis());
String googleIcon = "icon google";
MobileElement gLoginElement = getElementByName(googleIcon);
gLoginElement.click();
printLog("\nGoogle clicked.." + System.currentTimeMillis());
...
// Input Credentials for Google auth or select user from the auth list
// Assert.assertEquals("Hi test found.", "Test", "Test1");
}
public void loginWithIncorrectPassword() {
String passwordEntry = "//XCUIElementTypeApplication[@name=\"eCare Vault\"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeScrollView/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeSecureTextField";
MobileElement pwdEntryElement = getElementByXPath(passwordEntry);
String passwordString = "12345";
pwdEntryElement.sendKeys(passwordString);
printLog("\n{Priority=>2} Password entered..." + passwordString + " @ " + System.currentTimeMillis());
...
printLog("\nSend clicked..." + System.currentTimeMillis());
// Assert for incorrect pwd.
}
@Test(groups = {"google"}, priority = 12)
public void loginWithIncorrectPasswordGoogle() {
loginWithIncorrectPassword();
}
public void loginWithCorrectPassword() {
String passwordEntry = "//XCUIElementTypeApplication[@name=\"eCare Vault\"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeScrollView/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeSecureTextField";
MobileElement pwdEntryElement = getElementByXPath(passwordEntry);
String passwordString = "VALID PWD";
pwdEntryElement.sendKeys(passwordString);
printLog("\n{Priority=>6} Password entered..." + passwordString + " @ " + System.currentTimeMillis());
// XCUIElementTypeButton[@name="Send"]
String sendKey = "Send";
MobileElement sendKeyElement = getElementByName(sendKey);
sendKeyElement.click();
printLog("\nSend clicked..." + System.currentTimeMillis());
}
@Test(groups = {"google"}, priority = 16)
public void loginWithCorrectPasswordGoogle() {
loginWithCorrectPassword();
}
public void logoutButtonClicked() {
// This method will logout user from the app and loads the main screen from where user will be able to tap the Google/Facebook icon
System.out.println("\nLogged out from ECV..." + System.currentTimeMillis());
}
@Test(groups = {"google"}, priority = 19)
public void logoutButtonClickedGoogle() {
logoutButtonClicked();
}
@Test(groups = {"facebook"}, priority = 20)
public void loginWithFB() {
System.out.println("\nLogin with Facebook..." + System.currentTimeMillis());
if (driver == null) {
printLog("Test driver is null.");
try {
setup();
} catch (MalformedURLException e) {
// e.printStackTrace();
}
}
printLog("driver = " + driver);
System.out.println("\nLoading is null and not logged in.." + System.currentTimeMillis());
String fbIcon = "icon facebook";
MobileElement fbLoginElement = getElementByName(fbIcon);
fbLoginElement.click();
System.out.println("\nFacebook clicked.." + System.currentTimeMillis());
...
// "Log In with the Facebook App" button exists for FB app login
// "Log In with the Facebook App" -> Tap
...
continueLoginElement.click();
System.out.println("\nKalis loggedIn.." + System.currentTimeMillis());
}
System.out.println(
"\n{Priority=>1} Password screen found.." + pwdScreen.getText() + " " + System.currentTimeMillis());
// Assert.assertEquals("Hi test found.", "Test", "Test1");
}
@Test(groups = {"facebook"}, priority = 22)
public void loginWithIncorrectPasswordFB() {
loginWithIncorrectPassword();
}
@Test(groups = {"facebook"}, priority = 26)
public void loginWithCorrectPasswordFB() {
loginWithCorrectPassword();
}
@Test(groups = {"facebook"}, priority = 28)
public void homePageLoadedFB() {
homePageLoaded();
}
@Test(groups = {"facebook"}, priority = 29)
public void logoutButtonClickedFB() {
logoutButtonClicked();
}
private void printLog(String message) {
System.out.println(message);
}
}
Testng.xml示例
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="TestGoogle">
<groups>
<run>
<include name="google" />
</run>
</groups>
<classes>
<class name="login.googleLogin.AppiumTest" />
</classes>
</test> <!-- Test -->
<test name="TestFB">
<groups>
<run>
<include name="facebook" />
</run>
</groups>
<classes>
<class name="login.googleLogin.AppiumTest" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
当我右键单击 testng.xml 并以 TestNG Suite 运行测试时,应用程序会在第一次测试&#34; TestGoogle&#时重新启动34; 已完成,重启5-10秒后,应用程序继续运行并执行&#34; TestFacebook&#34; 的待处理测试用例。
当我结合Facebook和谷歌时,Google / Facebook的测试用例不会被执行。
<run>
<include name="google" />
<include name="facebook" />
</run>
请告诉我如何解决问题。