自动化框架,用于自动化从 Web 应用程序到移动应用程序的场景

我想知道一个工作框架或一种方法来自动化脚本,该脚本必须在网络和移动设备上运行单一场景。

假设情况是,您已使用前台网络应用程序预订了从果阿运送到德里的货物,并且您已收到货件编号。现在,交付团队有一个移动应用程序,他们使用该应用程序不断更新货件状态:从源站出发,在途中,到达目的地。

当交付团队更新移动应用程序上的状态时,当您作为用户跟踪货件编号时,此状态应反映在 Web 应用程序中。


素胚勾勒不出你
浏览 149回答 1
1回答

慕容3067478

我过去曾处理过类似的问题,其中测试用例需要在移动和网络浏览器平台上进行测试。您需要CreateDriver在一个类中实现两种不同的方法DriverManager- 一种用于 Appium 驱动程序(用于移动设备),另一种用于 Selenium WebDriver(用于 Web 浏览器)。您的测试用例需要指定何时从网络“切换”到移动设备,或从移动设备“切换”到网络。您还需要包含一种停止 Appium 服务器的方法,以便在从移动设备切换到 Web 时使用。这是一个简单的通用示例,说明了它的工作原理:public class DriverFactory{&nbsp; &nbsp; private static AppiumLocalService _appiumLocalService;&nbsp; &nbsp; // use Current instance to act as static DriverFactory class instance&nbsp; &nbsp; private static DriverFactory _current;&nbsp; &nbsp; public static DriverFactory Current => _current ?? (_current = new DriverFactory());&nbsp; &nbsp; public AndroidDriver<AppiumWebElement> CreateAndroidDriver()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; // start Appium server&nbsp; &nbsp; &nbsp; &nbsp; var builder = new AppiumServiceBuilder();&nbsp; &nbsp; &nbsp; &nbsp; _appiumLocalService = builder.UsingAnyFreePort().Build();&nbsp; &nbsp; &nbsp; &nbsp; _appiumLocalService.Start();&nbsp; &nbsp; &nbsp; &nbsp; // set desired capabilities or appium options here&nbsp; &nbsp; &nbsp; &nbsp; var options = new AppiumOptions {PlatformName = "Android"};&nbsp; &nbsp; &nbsp; &nbsp; // start AndroidDriver session&nbsp; &nbsp; &nbsp; &nbsp; var driver = new AndroidDriver<AppiumWebElement>(_appiumLocalService.ServiceUrl, options);&nbsp; &nbsp; &nbsp; &nbsp; return driver;&nbsp; &nbsp; }&nbsp; &nbsp; public void StopAppiumService()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; // stop appium server&nbsp; &nbsp; &nbsp; &nbsp; _appiumLocalService.Dispose();&nbsp; &nbsp; }&nbsp; &nbsp; public IWebDriver CreateSeleniumDriver()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; // create browser-specific webdriver here&nbsp; &nbsp; &nbsp; &nbsp; // return webdriver&nbsp; &nbsp; }}然后,您可以实现一个BaseTestFixture为您处理启动和停止每个驱动程序的驱动程序。该类还包含 Selenium WebDriver 和 Appium 驱动程序的实例。您编写的每个测试类都应该从此固定装置继承,以继承两个驱动程序实例。public class BaseTestFixture{&nbsp; &nbsp; public static AndroidDriver<AppiumWebElement> AppiumDriver { get;set; }&nbsp; &nbsp; public static IWebDriver SeleniumDriver { get set; }&nbsp; &nbsp; public void SetAppiumDriver()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; AppiumDriver = DriverFactory.Current.CreateAndroidDriver();&nbsp; &nbsp; }&nbsp; &nbsp; public void TearDownAppiumDriver()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; AppiumDriver.Close();&nbsp; &nbsp; &nbsp; &nbsp; AppiumDriver.Quit();&nbsp; &nbsp; &nbsp; &nbsp; DriverFactory.Current.StopAppiumService();&nbsp; &nbsp; }&nbsp; &nbsp; public void SetSeleniumDriver()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; SeleniumDriver = DriverFactory.Current.CreateSeleniumDriver();&nbsp; &nbsp; }&nbsp; &nbsp; public void TearDownSeleniumDriver()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; SeleniumDriver.Close();&nbsp; &nbsp; &nbsp; &nbsp; SeleniumDriver.Quit();&nbsp; &nbsp; }}最后——这是如何BaseTestFixture在测试类中使用的:using MyProject.BaseTestFixture;[TestFixture]public class MyTestClass : BaseTestFixture{&nbsp; &nbsp; [Test]&nbsp; &nbsp; public void ShouldStartBothDrivers()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; // set Appium driver -- we are testing with mobile&nbsp; &nbsp; &nbsp; &nbsp; SetAppiumDriver();&nbsp; &nbsp; &nbsp; &nbsp; // perform testing with Appium driver&nbsp; &nbsp; &nbsp; &nbsp; AppiumDriver.FindElement(.....);&nbsp; &nbsp; &nbsp; &nbsp; // finished mobile testing -- move to web browser&nbsp; &nbsp; &nbsp; &nbsp; TearDownAppiumDriver();&nbsp; &nbsp; &nbsp; &nbsp; // set Selenium driver -- web browser testing&nbsp; &nbsp; &nbsp; &nbsp; SetSeleniumDriver();&nbsp; &nbsp; &nbsp; &nbsp; // perform testing with Selenium driver&nbsp; &nbsp; &nbsp; &nbsp; SeleniumDriver.FindElement(....);&nbsp; &nbsp; &nbsp; &nbsp; // finished web browser testing -- close selenium driver&nbsp; &nbsp; &nbsp; &nbsp; TearDownSeleniumDriver();&nbsp; &nbsp; }}正如我所提到的,这是一个非常通用的示例,需要您进行自定义以满足您的特定需求。这只是如何处理两个驱动程序的示例架构。希望这可以帮助。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java