gpt4 book ai didi

WPF CodedUI 测试 : programmatically launching application

转载 作者:行者123 更新时间:2023-12-04 18:21:27 26 4
gpt4 key购买 nike

如果我记录将登录凭据输入到对话框中的操作并在 UImap1.uitests 中调用此 Submit()。自动生成的代码将如下所示:

 public void Launch()
{
#region Variable Declarations
WpfEdit uIUsernameBoxEdit = this.UIOCC600OILoginWindow.UIUsernameBoxEdit;
WpfEdit uIPasswordBoxEdit = this.UIOCC600OILoginWindow.UIPasswordBoxEdit;
WpfButton uIOKButton = this.UIOCC600OILoginWindow.UIOKButton;
#endregion

// Type 'username' in 'usernameBox' text box
uIUsernameBoxEdit.Text = this.LaunchParams.UIUsernameBoxEditText;

// Click 'passwordBox' text box
Mouse.Click(uIPasswordBoxEdit, new Point(63, 13));

// Type '********' in 'passwordBox' text box
Keyboard.SendKeys(uIPasswordBoxEdit, this.LaunchParams.UIPasswordBoxEditSendKeys, true);

// Click 'OK' button
Mouse.Click(uIOKButton, new Point(33, 14));
}

现在,如果我在 CodedUI 测试类中使用 ClassInitialize 修饰的方法手动启动应用程序,如下所示:
      [ClassInitialize()]
public static void MyTestInitialize(TestContext context)
{
Process.Start(@"C:\Program Files (x86)\MyCompany\MyApp.exe");
Playback.Wait(2000);

var uimap = new LaunchApplicationMap();
var loginParams = uimap.EnterLoginCredentialsParams;
loginParams.UIUsernameBoxEditText = "username";
loginParams.UIPasswordBoxEditSendKeys = Playback.EncryptText("password
");
uimap.Launch();
Playback.Wait(5000);
}

为什么我会得到如下所示的空异常?

enter image description here

这也是堆栈跟踪:
System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
Source=Microsoft.VisualStudio.TestTools.UITest.Framework
StackTrace:
at Microsoft.VisualStudio.TestTools.UITest.Framework.UITestService.TechnologyManagerByName(String technologyName)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.ValidateSearchProperties()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindControlIfNecessary()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetProperty(String propertyName, Object value)
at Microsoft.VisualStudio.TestTools.UITesting.WpfControls.WpfEdit.set_Text(String value)
at UITests.UIMaps.LaunchApplicationMapClasses.LaunchApplicationMap.Launch() in C:\dev\OCC600\Source - Copy\Tests\UITests\UIMaps\LaunchApplicationMap.Designer.cs:line 44
at UITests.LogsViewTests.MyTestInitialize(TestContext context) in C:\dev\OCC600\Source - Copy\Tests\UITests\LogsViewTests.cs:line 70
InnerException:

TIA。

最佳答案

您需要初始化播放引擎以在测试方法之外使用 CodedUI。该框架会在 testinitalize/cleanup 方法中自动初始化播放/清理,因此您看不到它。

ClassInitialize/AssemblyInitialize 发生在任何测试开始之前,因此您必须调用 Playback.Initialize()。

关于WPF CodedUI 测试 : programmatically launching application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10590785/

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