java - 同一类的第一次 @Test 失败后,所有测试都会自动失败

标签 java selenium mobile testng appium

我使用 TestNG + Selenium + Appium。 我遇到的问题是: 如果第一个 @Test 失败,则所有其余的自动失败并且执行将停止。

我尝试使用 @BecoreClass setUp 而不是在第一次失败后仍然在 @Test 进行设置。

我认为它跳过了所有其余的测试,因为它没有以正确的方式完成该过程(退出应用程序),这就是为什么我在 driver.quit 中添加了 @Aftermethod ,它会在失败后执行它方法。 但在第一次失败后,它仍然自动失败所有测试。

我需要有多个带有测试方法的@Test,这些测试方法将是单独的,具有单独的配置。如果第一个失败,它将继续执行 @Test 的其余部分(即使它们来自同一类),之后会给我一个结果。

package foundation;


import com.pageobjects.HeaderMenu;
import config.AppConfiguration;
import config.LogIn;
import config.DesiredCapabilitiesSetup;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.*;
import org.testng.asserts.SoftAssert;


import java.io.IOException;


public class AppiumTestTest {
    private AndroidDriver<AndroidElement> driver;

    private AOWebClient aoWeb;

    @SuppressWarnings("unused")
    public AppiumTestTest(AndroidDriver<AndroidElement> driver, AOWebClient aoWeb) {
        this.driver = driver;
        this.aoWeb = aoWeb;
        PageFactory.initElements(new AppiumFieldDecorator(driver), this);
    }

    @SuppressWarnings("unused")
    public AppiumTestTest() {
    }

    private SoftAssert softAssert = new SoftAssert();
/*
    @BeforeClass
    public void setUp() throws Exception {
    }
*/



    @Test
    public void checkInTest() throws Exception {

        driver = DesiredCapabilitiesSetup.startAppiumServer(
                AppConfiguration.newBuilder()
                        .setTimeSelection(false)
                        .setBirthday(true)
                        .build());
        AOWebClient aoWebClient = DesiredCapabilitiesSetup.getAOWeb();
        LogIn logIn = new LogIn(driver, aoWebClient);
        logIn.logIn();
    }




    @Test
    public void timeSelectionTest() throws Exception {

        driver = DesiredCapabilitiesSetup.startAppiumServer(
                AppConfiguration.newBuilder()
                        .setTimeSelection(true)
                        .setBirthday(true)
                        .build());
        AOWebClient aoWebClient = DesiredCapabilitiesSetup.getAOWeb();
        LogIn logIn = new LogIn(driver, aoWebClient);
        logIn.logIn();
    }
    @AfterMethod
    public void afterM(){
        driver.close();
        driver.quit();
    }


}

我期望的能力是:

package config;

import com.pageobjects.LaunchProgress;
import com.sun.javafx.tools.ant.DeployFXTask;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.json.simple.JSONObject;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeClass;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.TimeUnit;


public class DesiredCapabilitiesSetup {


    //Name of Android Device
    //public static String deviceName = "TestDevice";

    // Emulator
    //public static String deviceName = "One";

    //Path of App folder
    // public static String appLink = "/Users/af185125/FoundationApp/";


    //The name of Android application with format. (.apk).
    //public static String appName = "app331.apk";


    private static final String KEY_USE_TIME_SELECTION = "useTimeSelection";
    private static final String KEY_DISABLE_BIRTHDAY = "disableBirthday";

    @BeforeClass
    public static AndroidDriver<AndroidElement> startAppiumServer(AppConfiguration appConfiguration) throws IOException {
// Taking App/Device/Link path from *txt file located in the project //
        /*
        String appLink = FileUtils.readFileToString(new File("appConfigurations/appLink.txt"));
        String deviceName = FileUtils.readFileToString(new File("appConfigurations/deviceName.txt"));
        String appName = FileUtils.readFileToString(new File("appConfigurations/appName.txt"));
        */


        String appLink = FileUtils.readFileToString(new File("appConfigurations/appLink.txt"));
        String deviceName = FileUtils.readFileToString(new File("appConfigurations/deviceName.txt"));
        String appName = FileUtils.readFileToString(new File("appConfigurations/appName.txt"));

        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
        cap.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
        cap.setCapability(MobileCapabilityType.VERSION, "6.0");
        cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "4000");

        String configurationString = getConfigurationString(appConfiguration);
        cap.setCapability(AndroidMobileCapabilityType.OPTIONAL_INTENT_ARGUMENTS,"--es appium_config \"" + configurationString + "\"");

        //cap.setCapability("avd","nexus");
        File appSource = new File(appLink);
        File app = new File(appSource, appName);
        cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());



        AndroidDriver<AndroidElement> driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
        driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);




        LaunchProgress launch = new LaunchProgress(driver);
        launch.waitForLaunchScreenToLoad();


        return driver;

    }

    @SuppressWarnings("unchecked")
    private static String getConfigurationString(AppConfiguration appConfiguration) {
        JSONObject configuration = new JSONObject();
        configuration.put(KEY_USE_TIME_SELECTION, appConfiguration.timeSelection);
        configuration.put(KEY_DISABLE_BIRTHDAY, appConfiguration.birthday);
        return configuration.toJSONString();
    }

}

堆栈跟踪:

objc[20683]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Connected to the target VM, address: '127.0.0.1:58385', transport: 'socket'
[TestNG] Running:
  /Users/af185125/Library/Caches/IdeaIC2016.2/temp-testng-customsuite.xml

org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 80.28 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'WUSAF185125-G3D', ip: '153.86.242.30', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_91'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=/Users/af185125/android-ui-test/currentApp/appiumT.apk, appPackage=com.ao.demo.beta, networkConnectionEnabled=true, warnings={}, appWaitPackage=com.ao.demo.beta, appWaitActivity=com.ao.core.ui.launch.LaunchActivity, databaseEnabled=false, deviceName=ad071603280ea0c18d, version=6.0, fullReset=true, platform=LINUX, deviceUDID=ad071603280ea0c18d, appActivity=com.ao.core.ui.launch.LaunchActivity, desired={app=/Users/af185125/android-ui-test/currentApp/appiumT.apk, newCommandTimeout=4000, platformVersion=6.0, automationName=Appium, platformName=Android, deviceName=Automation, version=6.0, optionalIntentArguments=--es appium_config "{"useTimeSelection":false,"disableBirthday":true}", fullReset=true}, newCommandTimeout=4000, platformVersion=6.0.1, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, takesScreenshot=true, javascriptEnabled=true, platformName=Android, optionalIntentArguments=--es appium_config "{"useTimeSelection":false,"disableBirthday":true}"}]
Session ID: 30270d0f-8594-4ead-b5b6-56dfeee37f44
*** Element info: {Using=id, value=fasf.com}

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:51)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:67)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:413)
    at io.appium.java_client.DefaultGenericMobileDriver.findElementById(DefaultGenericMobileDriver.java:75)
    at io.appium.java_client.AppiumDriver.findElementById(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElementById(AndroidDriver.java:1)
    at org.openqa.selenium.By$ById.findElement(By.java:218)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:63)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
    at foundation.AppiumTestTest.checkInTest(AppiumTestTest.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:646)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1129)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:746)
    at org.testng.TestRunner.run(TestRunner.java:600)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1264)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1189)
    at org.testng.TestNG.runSuites(TestNG.java:1104)
    at org.testng.TestNG.run(TestNG.java:1076)
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:124)


org.openqa.selenium.WebDriverException: Method has not yet been implemented (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 7 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'WUSAF185125-G3D', ip: '153.86.242.30', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_91'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=/Users/af185125/android-ui-test/currentApp/appiumT.apk, appPackage=com.ao.demo.beta, networkConnectionEnabled=true, warnings={}, appWaitPackage=com.ao.demo.beta, appWaitActivity=com.ao.core.ui.launch.LaunchActivity, databaseEnabled=false, deviceName=ad071603280ea0c18d, version=6.0, fullReset=true, platform=LINUX, deviceUDID=ad071603280ea0c18d, appActivity=com.ao.core.ui.launch.LaunchActivity, desired={app=/Users/af185125/android-ui-test/currentApp/appiumT.apk, newCommandTimeout=4000, platformVersion=6.0, automationName=Appium, platformName=Android, deviceName=Automation, version=6.0, optionalIntentArguments=--es appium_config "{"useTimeSelection":false,"disableBirthday":true}", fullReset=true}, newCommandTimeout=4000, platformVersion=6.0.1, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, takesScreenshot=true, javascriptEnabled=true, platformName=Android, optionalIntentArguments=--es appium_config "{"useTimeSelection":false,"disableBirthday":true}"}]
Session ID: 30270d0f-8594-4ead-b5b6-56dfeee37f44

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:51)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:268)
    at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:521)
    at foundation.AppiumTestTest.afterM(AppiumTestTest.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:216)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:712)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1129)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:746)
    at org.testng.TestRunner.run(TestRunner.java:600)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1264)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1189)
    at org.testng.TestNG.runSuites(TestNG.java:1104)
    at org.testng.TestNG.run(TestNG.java:1076)
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:124)


Test ignored.
org.openqa.selenium.WebDriverException: Method has not yet been implemented (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 5 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'WUSAF185125-G3D', ip: '153.86.242.30', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_91'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=/Users/af185125/android-ui-test/currentApp/appiumT.apk, appPackage=com.ao.demo.beta, networkConnectionEnabled=true, warnings={}, appWaitPackage=com.ao.demo.beta, appWaitActivity=com.ao.core.ui.launch.LaunchActivity, databaseEnabled=false, deviceName=ad071603280ea0c18d, version=6.0, fullReset=true, platform=LINUX, deviceUDID=ad071603280ea0c18d, appActivity=com.ao.core.ui.launch.LaunchActivity, desired={app=/Users/af185125/android-ui-test/currentApp/appiumT.apk, newCommandTimeout=4000, platformVersion=6.0, automationName=Appium, platformName=Android, deviceName=Automation, version=6.0, optionalIntentArguments=--es appium_config "{"useTimeSelection":false,"disableBirthday":true}", fullReset=true}, newCommandTimeout=4000, platformVersion=6.0.1, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, takesScreenshot=true, javascriptEnabled=true, platformName=Android, optionalIntentArguments=--es appium_config "{"useTimeSelection":false,"disableBirthday":true}"}]
Session ID: 30270d0f-8594-4ead-b5b6-56dfeee37f44

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:51)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:268)
    at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:521)
    at foundation.AppiumTestTest.afterM(AppiumTestTest.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:216)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:712)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1129)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:746)
    at org.testng.TestRunner.run(TestRunner.java:600)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1264)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1189)
    at org.testng.TestNG.runSuites(TestNG.java:1104)
    at org.testng.TestNG.run(TestNG.java:1076)
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:124)

最佳答案

driver = DesiredCapabilitiesSetup.startAppiumServer... 移动到 @BeforeMethod。此外,如果您想使用不同的驱动程序进行测试,则必须添加参数化(例如用于组的 @BeforeMethod@DataProvider@Facotry) .

关于java - 同一类的第一次 @Test 失败后,所有测试都会自动失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40642927/

相关文章:

javascript - 主题 Sencha Touch - 需要指南针和 SSAS 吗?

html - 在开发人员工具中测试响应能力时,网站 react 完美,但不是以实际手机屏幕为中心?

java - 当两个对象的名称为 `out` 时,为什么我没有收到错误消息?

java - 如何将自定义 getView 绑定(bind)到 ListView 适配器?

python - 尝试在网站中查找 ID 并出现 'chrome not reachable' 错误

selenium - 如何使用Selenium WebDriver拍摄部分屏幕截图(框架)?

python - Selenium python - 元素在点不可点击

android 键盘显示后 jQuery 移动页脚或视口(viewport)大小错误

java - 需要帮助创建一个程序来找到最轻和最重的狗

java - 为什么我的字符串值不会返回?