I have written some code to verify that a user can login to a hotel booking platform & I also added a verification step. I get an error
on the Assert.IsTrue()
Method. Every other thing is fine in the code.
I did some research for a possible solution before stopping by.
Here is the solution I found on StackOverflow: Assert Method Error
I have added Microsoft.VisualStudio.QualityTools.UnitTestFramework to my project references and also added
using Microsoft.VisualStudio.TestTools.UnitTesting; & using NUnit.Framework; to my Using section of the code.
I get the following errors:
Severity Code Description Project File Line Suppression State Error CS0234 The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) PremierInn_Valid_User_Login c:\users\XXXX\onedrive\documents\visual studio 2015\Projects\PremierInn_Valid_User_Login\PremierInn_Valid_User_Login\Program.cs 5 Active
Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?) PremierInn_Valid_User_Login c:\users\XXXX\onedrive\documents\visual studio 2015\Projects\PremierInn_Valid_User_Login\PremierInn_Valid_User_Login\Program.cs 6 Active
I get the same error after removing the bindings - Microsoft.VisualStudio.TestTools.UnitTesting; & using NUnit.Framework.
And, finally here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System.Threading.Tasks;
namespace PremierInn_Valid_User_Login {
class Program {
static void Main(string[] args) {
//Instantiate Firefox Driver
var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("https://secure.premierinn.com/en/mypremierinn/home.action");
//Enter User Name - My Email Address
var user = driver.FindElement(By.Id("loginForm.username"));
user.SendKeys("[email protected]");
//Enter Password - Account Pasword
var pass = driver.FindElement(By.Id("loginForm.password"));
pass.SendKeys("Testing123");
//Click on Login button
driver.FindElement(By.Id("loginForm.button")).Click();
var loggedInHeader = driver.FindElement(By.Id("body-inner"));
Assert.IsTrue(loggedInHeader.Displayed, "The user was able to successfully login.");
}
}
}
Thank you for your help.
Suggestions:
You are trying to write a unit test, but on a main program instead of in a unit test project? Create unit test project. see here.
You are trying to use both NUnit and Microsoft Unit test framework? Choose one of them, not both.
You may need to refer to the NUnit Assembly documentation to run a test with NUnit.
NUnit QuickStart
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With