使用Appium启动整个测试套件

时间:2015-06-11 13:09:32

标签: java android appium

现在我正在尝试使用Appium自动化混合移动应用程序。 现在我使用GenyMotion或Android SDK模拟器在Android模拟器上运行测试套件,但是我遇到了两个问题。

当我逐个启动我的测试时,一次一个 - 一切都很好。有时即使在同时启动它们2或3时一切都还可以。

但是当我尝试启动整个测试套件(整个类都带有测试方法)时 - 会发生Appium会话的问题。

我的基本设置:

public class BaseAppTest {
    protected AppiumDriver driver;

    @BeforeMethod
    public void before() throws Exception
    {
        File appDir = new File("D:\\Build\\");
        File app = new File(appDir, "2015-06-10_13-09-03_amt-en_Development_234.apk");

        DesiredCapabilities capabilities = new DesiredCapabilities();       
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "192.168.56.101:5555");
        capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        capabilities.setCapability("autoWebviewTimeout", 5000);
        capabilities.setCapability("app", app.getAbsolutePath());

        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);

        Set<String> contextNames = driver.getContextHandles();       
        driver.context(contextNames.toArray()[1].toString()); // set context to WEBVIEW_1
        WebDriverRunner.setWebDriver(driver);


    }

    @AfterMethod
    public void afterMethod()
    {
       driver.quit();
    }
}

内部测试我使用Selenide,也使用从URL到URL和LocaleStorage注入的导航:

public class WGCTest extends BaseAppTest {

    @BeforeMethod
    public void before() throws Exception {
        super.before();
        Thread.sleep(2000);
        //driver.navigate().to(BaseSelectors.URL);
        LocalStorageInjector.clearStorage(getWebDriver());
        open(BaseSelectors.URL);
    }

}

和testSuite:

@BeforeMethod
public void before() throws Exception {
        super.before();
        Injections.injectionWeek0(getWebDriver());
        open(WGCSelectors.URL);
        //driver.navigate().to(WGCSelectors.URL);
        //WebDriverRunner.setWebDriver(driver);
    }


    @Test
    @Features(MyFeatures.WGC)
    @Stories("Clicking links")
    public static void clickingHowItWorksLink()
    {
        WGCTestMethods2.clickHowItWorksLink(weight85, weight300, feet5, inches0);
    }

    @Test
    @Features(MyFeatures.WGC)
    @Stories("Checking default structure")
    public static void checkDefaultStructure()
    {
        WGCTestMethods2.defaultStructureChecking();
    }

    @Test
    @Features(MyFeatures.WGC)
    @Stories("Filling fields and checking saving")
    public static void settingPreWeightFieldAndCheckChangesGotSaved() {
        WGCTestMethods2.settingPreWeightField(weight85);
    }

我认为设置或注释有问题,因为每个测试都是单独的......但是有什么问题?

请帮我找错!谢谢!

例外:

     org.openqa.selenium.remote.SessionNotFoundException: 
Command duration or timeout: 3 milliseconds
Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27 09:10:26'
System info: host: 'KOZLOVA7', ip: '192.168.2.87', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_45'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=D:\Build\2015-06-10_13-09-03_amt-en_Development_234.apk, networkConnectionEnabled=true, autoWebviewTimeout=5000, warnings={}, databaseEnabled=false, deviceName=emulator-5554, platform=LINUX, desired={app=D:\Build\2015-06-10_13-09-03_amt-en_Development_234.apk, autoWebviewTimeout=5000, platformVersion=4.4, automationName=Appium, platformName=Android, deviceName=emulator-5554}, platformVersion=4.4.4, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, browserName=Android, takesScreenshot=true, javascriptEnabled=true, platformName=Android}]
Session ID: 69af8a8f-83af-4c46-a7d1-56d6d4d31cf9
    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:422)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:162)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:508)
    at utils.LocalStorageInjector.LocalStorageInjector.clearStorage(LocalStorageInjector.java:21)
    at AppTests.BaseTests.WGCTest.before(WGCTest.java:17)
    at AppTests.WGCTestSuite02.before(WGCTestSuite02.java:36)

1 个答案:

答案 0 :(得分:1)

您收到此错误,因为已存在相同参数的会话。 请将注释从@BeforeMethod更改为@BeforeTest,将注释更改为@AfterTest。以这种方式,在整个测试套件之前/之后一次提供前后步骤。