OneTimetEardown不执行C#UI测试
我很难被拆除以执行的执行,该执行应该删除我的自动化在应用程序上创建的所有帐户。我选择使用OneTimetEardown,因此它执行一次,并且仅通过列表,但似乎并没有执行。这是代码,我把它放在错误的地方吗?如果我只将其添加到测试的末尾,则拆卸中的代码按原本打算工作。
namespace Ag.AutomatedRegression.UI.Tests.AccountsTests { [TestFixture] public class AccountsPageTests : BaseSetup { [OneTimeTearDown] public void CleanUpAccounts() { LogList.Add($"Entered the {MethodBase.GetCurrentMethod()}()."); for (int i = AccountsPageTests.accountIdList.Count - 1; i >= 0; i--) { if (AccountsPageTests.accountIdList.Count == 0) { LogList.Add("There were no ids in the list to delete."); break; } else { LogList.Add("Next Step: Clean Up accounts created this session."); PerformBrowserManagerAction.NavigateToURL(CommonSettings.Default.URL); PerformCommonStagesAction.CleanUpAccounts(CommonSettings.Default.UserName, CommonSettings.Default.EncryptedPassword, AccountsPageTests.accountIdList[i]); } LogList.Add("Account Cleanup was successful."); } } public static List accountIdList = new List(); [Test] public void CreateAccountTest() { LogList.Add($"Entered the {MethodBase.GetCurrentMethod()}()."); //Code to create account with account id string variable Assert.That(Success, Is.True, expectedMessage + "\r\n" + actualMessage); } } }
I am having trouble getting a teardown to execute that is supposed to delete all of the accounts my automation creates on our application. I elected to use a OneTimeTearDown so it executes once and just goes through the list but it doesn't seem to be executing. Here is the code, am I putting it in the wrong place maybe? The code in the teardown works as intended on its own if I just add it to the end of the test.
namespace Ag.AutomatedRegression.UI.Tests.AccountsTests { [TestFixture] public class AccountsPageTests : BaseSetup { [OneTimeTearDown] public void CleanUpAccounts() { LogList.Add($"Entered the {MethodBase.GetCurrentMethod()}()."); for (int i = AccountsPageTests.accountIdList.Count - 1; i >= 0; i--) { if (AccountsPageTests.accountIdList.Count == 0) { LogList.Add("There were no ids in the list to delete."); break; } else { LogList.Add("Next Step: Clean Up accounts created this session."); PerformBrowserManagerAction.NavigateToURL(CommonSettings.Default.URL); PerformCommonStagesAction.CleanUpAccounts(CommonSettings.Default.UserName, CommonSettings.Default.EncryptedPassword, AccountsPageTests.accountIdList[i]); } LogList.Add("Account Cleanup was successful."); } } public static List accountIdList = new List(); [Test] public void CreateAccountTest() { LogList.Add($"Entered the {MethodBase.GetCurrentMethod()}()."); //Code to create account with account id string variable Assert.That(Success, Is.True, expectedMessage + "\r\n" + actualMessage); } } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的陈述索引
并不能执行您想要的。它永远不会处理列表项目0,如果只有1个项目,则不会显示任何内容。
在心理上逐步逐步逐步逐步逐步逐步逐步完成
。 0'至 i> = 0`
The indexing on your statement
doesn't do what you want. It will never process list item 0 and if there is only 1 item, nothing will show.
Step through it mentally, assuming one item
Change
i > 0' to
i >= 0`正如我们已经在评论中讨论的那样,请尝试是否格式化是否是您班级的问题:
As we were already discussing in the comments, please try whether formatting is an issue of your class:
在MU88的回答之后,格式是正确的,但这并不能解决拆卸,我最终使其成为标准的拆卸,而这似乎已经解决了问题。
Formatting was correct after mu88's answer, but that didn't fix the teardown, I ended up making it a standard Teardown instead and that seems to have resolved the issue.