[英]How to write a selenium c# x unit test for performing crud operations without making changes to the actual database?
My program has a page that displays a table as well as buttons to add/edit/delete users.我的程序有一个显示表格的页面以及添加/编辑/删除用户的按钮。 I wrote selenium tests that simulate clicking those buttons and entering in user info and submitting the form.
我编写了 selenium 测试来模拟单击这些按钮并输入用户信息并提交表单。 The problem with this is I am making changes to my database as well as I have to keep changing the values of the keys I am sending in each time I run my tests.
问题是我正在对我的数据库进行更改,并且我必须在每次运行测试时不断更改我发送的键的值。 I don't know how to simulate/test these cases without doing so.
如果不这样做,我不知道如何模拟/测试这些案例。 This is my test for adding a user:
这是我添加用户的测试:
[Fact]
public void AddUserSuccessfully()
{
var email = "anotheradd@gmail.com";
using IWebDriver driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl(BaseUrl.testUserUrl);
var login = new Login(driver);
login.EnterEmail();
login.EnterPassword();
login.HitSubmit();
var users = new Users(driver);
users.ClickOnAddUser();
users.EnterFirstName("Anita");
users.EnterLastName("Work");
users.EnterEmail(email);
users.EnterPassword("P*$sW0rd");
users.ConfirmPassword("P*$sW0rd");
users.EnterRole("Developer");
Pause.SimulatePause();
var modal = new Modal(driver);
modal.SubmitForm();
driver.Navigate().Refresh();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
var emailFound = wait.Until((d) => d.PageSource.Contains(email));
Assert.True(emailFound);
driver.Quit();
}
If anyone has any suggestions, I'd appreciate it.如果有人有任何建议,我将不胜感激。 Thank you,
谢谢,
Hope you are not running this on PROD, but as others have suggested and if you have read/write access to you test database write you logic to delete user from table in your clean up code.希望您没有在 PROD 上运行它,但正如其他人所建议的那样,如果您对测试数据库具有读/写访问权限,请在清理代码中编写逻辑以从表中删除用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.