gpt4 book ai didi

java - 使用 Appium 启动整个测试套件

转载 作者:行者123 更新时间:2023-11-30 02:05:13 25 4
gpt4 key购买 nike

现在我正在尝试使用 Appium 自动化混合移动应用程序。目前,我在 Android 模拟器上运行测试套件,使用 GenyMotion 或 Android SDK 模拟器,但我对这两者都有问题。

当我一项一项地启动测试时,一次一项——一切正常。有时即使同时启动 2 或 3 个,一切都正常。

但是当我尝试启动整个测试套件(带有测试方法的整个类)时 - Appium session 出现问题。

我的基本设置:

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 注入(inject):

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);
}

}

和测试套件:

@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);
}

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

请大家帮我找出错误!谢谢!

异常(exception):

     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)

最佳答案

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

关于java - 使用 Appium 启动整个测试套件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30781755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com