Skip to content

Commit a10d1aa

Browse files
add examples
increase versions
1 parent af3c84a commit a10d1aa

60 files changed

Lines changed: 69207 additions & 10122 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

GenerateLoadTestProjects/Program.cs

Lines changed: 96 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace GenerateLoadTestProjects
1818
{
1919
public class Program
2020
{
21-
public static void Main(string[] args) => GenerateLoadTestsNUnit();
21+
public static void Main(string[] args) => GenerateLoadTestsMsTest();
2222

2323
////private static void GenerateLoadTestsNUnit()
2424
////{
@@ -53,95 +53,45 @@ public class Program
5353
//// File.WriteAllText(fileLocation, sb.ToString());
5454
//// }
5555
////}
56-
57-
private static void GenerateLoadTestsNUnit()
58-
{
59-
// MSTEST
60-
var numberOfTestFiles = 2;
61-
var numberOfTests = 1000;
62-
var deployLocation = @"D:\SourceCode\Meissa\LoadTestsProject.NUnit\";
63-
for (var i = 1; i < numberOfTestFiles; i++)
64-
{
65-
var sb = new StringBuilder();
66-
sb.AppendLine("using System;");
67-
sb.AppendLine("using System.Threading;");
68-
sb.AppendLine("using NUnit.Framework;");
69-
sb.AppendLine("using System.IO;");
70-
sb.AppendLine("using OpenQA.Selenium;");
71-
sb.AppendLine("using OpenQA.Selenium.Support.UI;");
72-
sb.AppendLine("using System.Reflection;");
73-
sb.AppendLine();
74-
sb.AppendLine("namespace LoadTestsProject");
75-
sb.AppendLine("{");
76-
sb.AppendLine(" [TestFixture]");
77-
sb.AppendLine($" public class Cosmos{i}Tests");
78-
sb.AppendLine(" {");
79-
for (var j = 0; j < numberOfTests; j++)
80-
{
81-
sb.AppendLine(" ");
82-
sb.AppendLine(" [Test]");
83-
sb.AppendLine($" public void TestMethod{j}()");
84-
sb.AppendLine(" {");
85-
sb.AppendLine(" var driver = DriverFactory.GetDriver();");
86-
sb.AppendLine(" var assembly = Assembly.GetExecutingAssembly();");
87-
sb.AppendLine(" string path = Path.GetDirectoryName(assembly.Location);");
88-
sb.AppendLine(" string pageFilePath = Path.Combine(path, \"button.html\");");
89-
sb.AppendLine(" driver.Navigate().GoToUrl(new System.Uri(pageFilePath, uriKind: System.UriKind.Absolute));");
90-
sb.AppendLine(" var buttonElement = driver.FindElement(By.Id(\"myButton\"));");
91-
sb.AppendLine(" buttonElement.Click();");
92-
sb.AppendLine(" var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));");
93-
sb.AppendLine(" wait.Until(d => d.FindElement(By.Id(\"myButton\")).GetAttribute(\"value\").Equals(\"Stop\"));");
94-
sb.AppendLine(" driver.Quit();");
95-
sb.AppendLine(" }");
96-
}
97-
sb.AppendLine(" }");
98-
sb.AppendLine("}");
99-
var fileLocation = Path.Combine(deployLocation, $"Cosmos{i}Tests.cs");
100-
File.WriteAllText(fileLocation, sb.ToString());
101-
}
102-
}
10356

104-
////private static void GenerateLoadTestsMsTest()
57+
//// private static void GenerateLoadTestsNUnit()
10558
////{
10659
//// // MSTEST
10760
//// var numberOfTestFiles = 2;
10861
//// var numberOfTests = 1000;
109-
//// var deployLocation = @"D:\SourceCode\AutomateThePlanet\Meissa\LoadTestsProject.NUnit";
62+
//// var deployLocation = @"D:\SourceCode\Meissa\LoadTestsProject.NUnit\";
11063
//// for (var i = 1; i < numberOfTestFiles; i++)
11164
//// {
11265
//// var sb = new StringBuilder();
11366
//// sb.AppendLine("using System;");
11467
//// sb.AppendLine("using System.Threading;");
115-
//// sb.AppendLine("using Microsoft.VisualStudio.TestTools.UnitTesting;");
68+
//// sb.AppendLine("using NUnit.Framework;");
11669
//// sb.AppendLine("using System.IO;");
11770
//// sb.AppendLine("using OpenQA.Selenium;");
11871
//// sb.AppendLine("using OpenQA.Selenium.Support.UI;");
11972
//// sb.AppendLine("using System.Reflection;");
12073
//// sb.AppendLine();
12174
//// sb.AppendLine("namespace LoadTestsProject");
12275
//// sb.AppendLine("{");
123-
//// sb.AppendLine(" [TestClass]");
76+
//// sb.AppendLine(" [TestFixture]");
12477
//// sb.AppendLine($" public class Cosmos{i}Tests");
12578
//// sb.AppendLine(" {");
126-
//// sb.AppendLine(" [TestInitialize]");
127-
//// sb.AppendLine(" public void TestInit()");
128-
//// sb.AppendLine(" {");
129-
//// sb.AppendLine(" var assembly = Assembly.GetExecutingAssembly();");
130-
//// sb.AppendLine(" string path = Path.GetDirectoryName(assembly.Location);");
131-
//// sb.AppendLine(" string pageFilePath = Path.Combine(path, \"button.html\");");
132-
//// sb.AppendLine(" DriverFactory.GetDriver().Navigate().GoToUrl(new System.Uri(pageFilePath, uriKind: System.UriKind.Absolute));");
133-
//// sb.AppendLine(" }");
13479
//// for (var j = 0; j < numberOfTests; j++)
13580
//// {
13681
//// sb.AppendLine(" ");
137-
//// sb.AppendLine(" [TestMethod]");
82+
//// sb.AppendLine(" [Test]");
13883
//// sb.AppendLine($" public void TestMethod{j}()");
13984
//// sb.AppendLine(" {");
14085
//// sb.AppendLine(" var driver = DriverFactory.GetDriver();");
86+
//// sb.AppendLine(" var assembly = Assembly.GetExecutingAssembly();");
87+
//// sb.AppendLine(" string path = Path.GetDirectoryName(assembly.Location);");
88+
//// sb.AppendLine(" string pageFilePath = Path.Combine(path, \"button.html\");");
89+
//// sb.AppendLine(" driver.Navigate().GoToUrl(new System.Uri(pageFilePath, uriKind: System.UriKind.Absolute));");
14190
//// sb.AppendLine(" var buttonElement = driver.FindElement(By.Id(\"myButton\"));");
14291
//// sb.AppendLine(" buttonElement.Click();");
14392
//// sb.AppendLine(" var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));");
14493
//// sb.AppendLine(" wait.Until(d => d.FindElement(By.Id(\"myButton\")).GetAttribute(\"value\").Equals(\"Stop\"));");
94+
//// sb.AppendLine(" driver.Quit();");
14595
//// sb.AppendLine(" }");
14696
//// }
14797
//// sb.AppendLine(" }");
@@ -150,5 +100,90 @@ private static void GenerateLoadTestsNUnit()
150100
//// File.WriteAllText(fileLocation, sb.ToString());
151101
//// }
152102
////}
103+
104+
private static void GenerateLoadTestsMsTest()
105+
{
106+
// MSTEST
107+
var numberOfTestFiles = 2;
108+
var numberOfTests = 1000;
109+
var deployLocation = @"D:\SourceCode\Meissa\LoadTestsProject";
110+
for (var i = 1; i < numberOfTestFiles; i++)
111+
{
112+
var sb = new StringBuilder();
113+
sb.AppendLine("using System;");
114+
sb.AppendLine("using Microsoft.VisualStudio.TestTools.UnitTesting;");
115+
sb.AppendLine("using System.IO;");
116+
sb.AppendLine("using OpenQA.Selenium;");
117+
sb.AppendLine("using OpenQA.Selenium.Support.UI;");
118+
sb.AppendLine("using System.Reflection;");
119+
sb.AppendLine();
120+
sb.AppendLine("namespace LoadTestsProject");
121+
sb.AppendLine("{");
122+
sb.AppendLine(" [TestClass]");
123+
sb.AppendLine($" public class CheckoutPage{i}Tests");
124+
sb.AppendLine(" {");
125+
sb.AppendLine(" ");
126+
sb.AppendLine(" private string _pageFilePath;");
127+
sb.AppendLine(" ");
128+
sb.AppendLine(" [TestInitialize]");
129+
sb.AppendLine(" public void TestInit()");
130+
sb.AppendLine(" {");
131+
sb.AppendLine(" var assembly = Assembly.GetExecutingAssembly();");
132+
sb.AppendLine(" string path = Path.GetDirectoryName(assembly.Location);");
133+
sb.AppendLine(" string pageFilePath = Path.Combine(path, \"checkout-page\", \"index.html\");");
134+
sb.AppendLine(" _pageFilePath = Path.Combine(path, \"checkout-page\", \"index.html\");");
135+
sb.AppendLine(" }");
136+
for (var j = 0; j < numberOfTests; j++)
137+
{
138+
sb.AppendLine(" ");
139+
sb.AppendLine(" [TestMethod]");
140+
sb.AppendLine($" public void SuccessfullyPruchaseItem{j}()");
141+
sb.AppendLine(" {");
142+
sb.AppendLine(" var driver = DriverFactory.GetDriver();");
143+
sb.AppendLine(" driver.Navigate().GoToUrl(new System.Uri(_pageFilePath, uriKind: System.UriKind.Absolute));");
144+
sb.AppendLine(" try");
145+
sb.AppendLine(" {");
146+
sb.AppendLine(" var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));");
147+
sb.AppendLine(" wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(StaleElementReferenceException));");
148+
sb.AppendLine(" wait.Until(d => d.FindElement(By.Id(\"firstName\")) != null);");
149+
sb.AppendLine(" var firstName = driver.FindElement(By.Id(\"firstName\"));");
150+
sb.AppendLine(" firstName.SendKeys(\"Anton\");");
151+
sb.AppendLine(" var lastName = driver.FindElement(By.Id(\"lastName\"));");
152+
sb.AppendLine(" lastName.SendKeys(\"Angelov\");");
153+
sb.AppendLine(" var userName = driver.FindElement(By.Id(\"username\"));");
154+
sb.AppendLine(" userName.SendKeys(\"angelovstanton\");");
155+
sb.AppendLine(" var address = driver.FindElement(By.Id(\"address\"));");
156+
sb.AppendLine(" address.SendKeys(\"Bulgarsko Opulchenie 76 B\");");
157+
sb.AppendLine(" var email = driver.FindElement(By.Id(\"email\"));");
158+
sb.AppendLine(" email.SendKeys(\"aangelov@bellatrix.solutions\");");
159+
sb.AppendLine(" var countriesSelect = new SelectElement(driver.FindElement(By.Id(\"country\")));");
160+
sb.AppendLine(" countriesSelect.SelectByText(\"United States\");");
161+
sb.AppendLine(" var statesSelect = new SelectElement(driver.FindElement(By.Id(\"state\")));");
162+
sb.AppendLine(" statesSelect.SelectByText(\"California\");");
163+
sb.AppendLine(" var zip = driver.FindElement(By.Id(\"zip\"));");
164+
sb.AppendLine(" zip.SendKeys(\"1000\");");
165+
sb.AppendLine(" var ccname = driver.FindElement(By.Id(\"cc-name\"));");
166+
sb.AppendLine(" ccname.SendKeys(\"Anton Angelov\");");
167+
sb.AppendLine(" var ccnumber = driver.FindElement(By.Id(\"cc-number\"));");
168+
sb.AppendLine(" ccnumber.SendKeys(\"5610591081018250\");");
169+
sb.AppendLine(" var ccexpiration = driver.FindElement(By.Id(\"cc-expiration\"));");
170+
sb.AppendLine(" ccexpiration.SendKeys(\"20/10/2020\");");
171+
sb.AppendLine(" var cccvv = driver.FindElement(By.Id(\"cc-cvv\"));");
172+
sb.AppendLine(" cccvv.SendKeys(\"888\");");
173+
sb.AppendLine(" var proceedButton = driver.FindElement(By.XPath(\"/html/body/div/div[2]/div[2]/form/button\"));");
174+
sb.AppendLine(" proceedButton.Click();");
175+
sb.AppendLine(" }");
176+
sb.AppendLine(" finally");
177+
sb.AppendLine(" {");
178+
sb.AppendLine(" driver.Quit();");
179+
sb.AppendLine(" }");
180+
sb.AppendLine(" }");
181+
}
182+
sb.AppendLine(" }");
183+
sb.AppendLine("}");
184+
var fileLocation = Path.Combine(deployLocation, $"CheckoutPage{i}Tests.cs");
185+
File.WriteAllText(fileLocation, sb.ToString());
186+
}
187+
}
153188
}
154189
}

0 commit comments

Comments
 (0)