Automated tests IOSDrive变为null,Appium TestNG测试在这两者之间重新启动应用程序

Automated tests IOSDrive变为null,Appium TestNG测试在这两者之间重新启动应用程序,automated-tests,testng,appium,appium-ios,testng-eclipse,Automated Tests,Testng,Appium,Appium Ios,Testng Eclipse,我面临着appium测试组的问题。我已经为我的应用程序编写了多个测试用例,并且一次运行不同的测试集 基本上,我的测试流程是:使用Google=>InputPassword=>Logout登录 然后,对于另一个设置,使用Facebook登录时使用相同的流 下面是在AppiumTest.java文件中编写的代码 @Test public class AppiumTest { IOSDriver<MobileElement> driver = null; public

我面临着appium测试组的问题。我已经为我的应用程序编写了多个测试用例,并且一次运行不同的测试集

基本上,我的测试流程是:使用Google=>InputPassword=>Logout登录 然后,对于另一个设置,使用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);
    }
} 
<?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 -->
@测试
公共类应用程序测试{
IOSDriver-driver=null;
设备的公共期望功能(字符串设备代码){
DesiredCapabilities=新的DesiredCapabilities();
能力。设置能力(“平台名”、“iOS”);
capabilities.setCapability(“udid”,“某些有效的udid”);//7+
能力。设置能力(“平台版”、“10.3.3”);
能力。设置能力(“应用程序”、“包路径”);
能力。设置能力(“noReset”,false);
setCapability(“showXcodeLog”,true);
setCapability(“clearSystemFiles”,false);
...
返回能力;
}
@BeforeSuite(groups={“google”})//删除套件也不会产生任何效果
public void setup()引发畸形的DurException{
System.out.print(“设置驱动程序。\n”);
DesiredCapabilities=capabilitiesForDevice(“iPhone 5S”);
字符串url=”http://0.0.0.0:4723/wd/hub";
驱动程序=新的IOSDriver(新的URL,能力);
}
@AfterSuite(组={“facebook”})
//删除套件也不会产生任何效果
//在两次测试执行之间,未调用此方法
公共无效拆卸(){
System.out.println(“AfterSuite…退出驱动程序…”);
driver.quit();
}
公共MobileElement getElementByName(字符串名称){
试一试{
MobileElement theElement=(MobileElement)(新的WebDriverWait(驱动程序,30))
。直到(预期条件。元素的可视性已定位(按。名称(name)));
返回元素;
}捕获(例外e){
//e.printStackTrace();
}
返回null;
}
公共MobileElement getElementByXPath(字符串xpath){
试一试{
MobileElement theElement=(MobileElement)(新的WebDriverWait(驱动程序,30))
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath));
返回元素;
}捕获(例外e){
//e.printStackTrace();
}
返回null;
}
@测试(组={“google”},优先级=1)
public void loginWithGoogle(){
if(驱动程序==null){
printLog(“测试驱动程序为空”);
试一试{
设置();
}捕获(格式错误){
//e.printStackTrace();
}
}
打印日志(“驱动程序=”+驱动程序);
printLog(“\n加载为空且未登录..”+System.currentTimeMillis());
字符串googleIcon=“icon google”;
MobileElement-gLoginElement=getElementByName(谷歌图标);
gloginement.click();
打印日志(“\n日志单击..”+System.currentTimeMillis());
...
//输入GoogleAuth的凭据或从auth列表中选择user
//Assert.assertEquals(“找到了Hi测试”,“测试”,“测试1”);
}
public void login密码不正确(){
String passwordEntry=“//XUIElementTypeApplication[@name=\“eCare Vault\”]/XUIElementTypeWindow[1]/XUIElementTypeOther/XUIElementTypeOther/XUIElementTypeOther/XUIElementTypeOther/XUIElementTypeOther/XUIElementTypeOther/XUIElementTypeSecureTextField”;
MobileElement pwdEntryElement=getElementByXPath(passwordEntry);
字符串passwordString=“12345”;
pwdEntryElement.sendKeys(密码字符串);
printLog(“\n{Priority=>2}输入的密码…”+passwordString+“@”+System.currentTimeMillis());
...
打印日志(“\n点击发送…”+System.currentTimeMillis());
//断言不正确的pwd。
}
@测试(组={“google”},优先级=12)
public void login密码不正确Google(){
登录时密码不正确();
}
public void loginWithCorrectPassword(){
String passwordEntry=“//XUIElementTypeApplication[@name=\“eCare Vault\”]/XUIElementTypeWindow[1]/XUIElementTypeOther/XUIElementTypeOther/XUIElementTypeOther/XUIElementTypeOther/XUIElementTypeOther/XUIElementTypeOther/XUIElementTypeSecureTextField”;
MobileElement pwdEntryElement=getElementByXPath(passwordEntry);
String passwordString=“VALID PWD”;
pwdEntryElement.sendKeys(密码字符串);
printLog(“\n{Priority=>6}输入的密码…”+passwordString+“@”+System.currentTimeMillis());
//XUIElementTypeButton[@name=“发送”]
字符串sendKey=“Send”;
MobileElement sendKeyElement=getElementByName(sendKey);
sendKeyElement.click();
打印日志(“\n点击发送…”+System.currentTimeMillis());
}
@测试(组={“google”},优先级=16)
public void loginWithCorrectPasswordGoogle(){
loginWithCorrectPassword();
}
公共作废logoutButtonClicked(){
//此方法将用户从应用程序中注销,并加载主屏幕,用户可以在主屏幕上点击Google/Facebook图标
System.out.println(“\n从ECV中注销…”+System.currentTimeMillis());
}
@测试(组={“google”},优先级=19)
public void logout按钮clickedGoogle(){
logoutButtonClicked();
}
@测试(组={“facebook”},优先级=20)
public void loginWithFB(){
System.out.println(“\n登录Facebook…”+System.currentTimeMillis());
if(驱动程序==null){
printLog(“测试驱动程序为空”);
tr
<run>
                <include name="google" />
                <include name="facebook" />
            </run>