Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am hoping I can get some insight to a issue I have been struggling to resolve. I am new to c# Nunit and Visual studio.
I have an XML storing usernames and XML storing passwords and .resx file in Visual Studio storing all the browser names.
Every password and username has to be parallel tested against each browser before proceeding to pick up the next set of username and passwords.For this I have used IEnumerable to yield return TestCaseData.

public class TestBase
{
public IWebDriver webDriver;
public static string Pass1 { get; private set; }

public static void Main(string[] args)
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(@"C:xxxxx\UserNamePassword.xml");
XmlNode node1 = xDoc.SelectSingleNode("//Test/DataRow");
XmlNode node3 = xDoc.SelectSingleNode("//Test");
XmlNode root = xDoc.DocumentElement;
string[] namesArray = new string[node1.ChildNodes.Count];
int i = node1.ChildNodes.Count;// count the number of datarows in the xml

ReturnValuesToTest(node3);
}


public static IEnumerable<testcasedata> ReturnValuesToTest(XmlNode node3)
{

foreach (XmlNode node in node3)
{

List<string> newpassword = new List<string>();
IEnumerator<string> newUSer = UsernameXmlDataDriven(node).GetEnumerator();
// var newUSer = UsernameXmlDataDriven(node).GetEnumerator();
while (newUSer.MoveNext()) // Select the first user name
{
var newuser = new List<string>();//adding to username to var newuser list
newuser.Add(newUSer.Current);// add all the user to the list
string User1 = newUSer.Current;//User1 will have the current user name

IEnumerator<string> newPass = PasswordXmlDataDriven(node).GetEnumerator();
//var newPass = PasswordXmlDataDriven(node).GetEnumerator();//now call the password
while (newPass.MoveNext())
{
newuser.Add(newPass.Current);// add all the password to the list
string Pass1 = newPass.Current;
}

String[] browsers = May3rdXML.AutomationSetting.BrowsersToRunWith.Split(',');


foreach (String b in browsers)
{
newuser.Add(b);// newuser is a list with user,password,browser


yield return new TestCaseData( User1, Pass1, b);
}
}

}
}

public static IEnumerable<string> UsernameXmlDataDriven(XmlNode node3)// node 1 is DataRow


{


foreach (XmlNode childnode in node3.SelectSingleNode("Username"))
{


yield return childnode.InnerText;// returning only the Usernames


}

}

public static IEnumerable<string> PasswordXmlDataDriven(XmlNode node3)// node 1 is DataRow

{


foreach (XmlNode childnode in node3.SelectSingleNode("Password"))
{


yield return childnode.InnerText;// returning only the Usernames


}

}




}
}

My tests are in a seperate class called LoginTestClass.cs
and Verify_Login will use the testdata returned to carry out Login tests in different browsers .
Test:
[TestFixture]
[Parallelizable]

public class LoginTestClass : TestBase
{

[TestCaseSource(typeof(TestBase), "ReturnValuesToTest")]
public static void Verify_Login(string newuser, string newpass, string browsername)
{


if (newuser[0].ToString() == null)
{
throw new NullReferenceException("no value");
}
if (newpass.ToString() == null)
{
throw new NullReferenceException("no value");
}
TestBase parentref = new TestBase();// declare a class of parent class





if (browsername.Equals("IE"))
{

parentref.webDriver = new
InternetExplorerDriver(@"U:xxxx/Win32_3.11.1");

}
else
if (browsername.Equals("Chrome"))
{
parentref.webDriver = new ChromeDriver(@"C:xxxx\chromedriver_win32");


}

What I have tried:

I have tried the below:
1.yield return new TestCaseData(new object[] { newuser[0], newuser[1], newuser[2] })
where newuser is a list and stores username,password and browsername.
Posted
Comments
Richard Deeming 14-Jun-18 13:29pm    
So there's no connection between the usernames, passwords, and browsers; you just want the cross-product of all three sets?
Member 13871081 18-Jun-18 10:57am    
I am trying to test all browsers with different combinations of usernames and passwords using parameterised NUnit testcasedata to the Test in parallel.
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900