I'm writing negative tests for checking content of error message shown to the user. There are two languages in app: english and german. The test works but the code for checking each language looks like this:
//Check if modal dialog with error message is shown
string currentLanguage = loginPage.currentLanguage.Text;
string modalMessage = loginPage.errorMsgModalDialogTitle.Text;
try
{
Assert.True(!string.IsNullOrEmpty(modalMessage));
test.Log(Status.Pass, "Office365 login has failed and modal dialog was shown to user!");
test.Log(Status.Info, "Checking modal dialog error message...");
switch (currentLanguage)
{
//Current language is english
case "German":
try
{
Assert.AreEqual(modalMessage, "User does not exist!");
test.Log(Status.Pass, "Modal dialog message title verified! Message title: '" + modalMessage + "'");
}
catch(AssertionException)
{
test.Log(Status.Fail, "Modal dialog did not contain message title: '" + modalMessage + "'");
}
break;
//Current language is german
case "English":
try
{
Assert.AreEqual(modalMessage, "Benutzer existiert nicht!");
test.Log(Status.Pass, "Modal dialog message title and text verified! Message title: '" + modalMessage + "'");
}
catch (AssertionException)
{
test.Log(Status.Fail, "Modal dialog did not contain message title: '" + modalMessage + "'");
}
break;
}
}
As you can see, the code to check the title of modal dialog in both languages is kinda too big and there will be negative tests with even more error messages to check in both languages.
Is there a way to somehow refractor this code and make it simpler or cleaner? Could I create some helper method that just takes current language as parameter, message and expected message and just return true or false?
Aucun commentaire:
Enregistrer un commentaire