Skip to content

Commit 4818825

Browse files
update usage of builders, align syntax, fix tests
fix bugs in web test form
1 parent b68088a commit 4818825

16 files changed

+530
-370
lines changed

Testimize.Tests/RealWorldExamples/ExploratoryModeCountriesGraphQLTests.cs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,50 @@
1313
// <site>https://automatetheplanet.com/</site>
1414

1515
using RestSharp;
16-
using System.Collections.Generic;
1716
using System;
18-
using Testimize.Contracts;
19-
using Testimize.OutputGenerators;
17+
using System.Collections.Generic;
2018
using Testimize.Parameters.Core;
19+
using Testimize.OutputGenerators;
20+
using Testimize.Usage;
2121

2222
namespace Testimize.Tests.RealWorld;
2323

2424
[TestFixture]
2525
public class ExploratoryModeCountriesGraphQLTests
2626
{
27-
public static List<IInputParameter> ABCGeneratedTestParameters() =>
28-
TestimizeInputBuilder
29-
.Start()
30-
.AddSingleSelect(s => s
31-
.Valid("US")
32-
.Valid("BG")
33-
.Valid("FR")
34-
.Invalid("XX").WithoutMessage()
35-
.Invalid("U1").WithoutMessage()
36-
.Invalid("").WithoutMessage())
37-
.AddSingleSelect(s => s
38-
.Valid("en")
39-
.Valid("fr")
40-
.Valid("de")
41-
.Invalid("zz").WithoutMessage()
42-
.Invalid("123").WithoutMessage())
43-
.AddSingleSelect(s => s
44-
.Valid("EU")
45-
.Valid("AF")
46-
.Valid("AS")
47-
.Invalid("999").WithoutMessage()
48-
.Invalid("X").WithoutMessage()
49-
.Invalid("").WithoutMessage())
50-
.Build();
27+
public static List<TestCase> ConfigureEngine() =>
28+
TestimizeEngine.Configure(
29+
parameters => parameters
30+
.AddSingleSelect(s => s
31+
.Valid("US")
32+
.Valid("BG")
33+
.Valid("FR")
34+
.Invalid("XX").WithoutMessage()
35+
.Invalid("U1").WithoutMessage()
36+
.Invalid("").WithoutMessage())
37+
.AddSingleSelect(s => s
38+
.Valid("en")
39+
.Valid("fr")
40+
.Valid("de")
41+
.Invalid("zz").WithoutMessage()
42+
.Invalid("123").WithoutMessage())
43+
.AddSingleSelect(s => s
44+
.Valid("EU")
45+
.Valid("AF")
46+
.Valid("AS")
47+
.Invalid("999").WithoutMessage()
48+
.Invalid("X").WithoutMessage()
49+
.Invalid("").WithoutMessage()),
50+
settings =>
51+
{
52+
settings.Mode = TestGenerationMode.HybridArtificialBeeColony;
53+
settings.TestCaseCategory = TestCaseCategory.Validation;
54+
}).Generate();
5155

5256
[Test]
53-
[ABCTestCaseSource(nameof(ABCGeneratedTestParameters), TestCaseCategory.Validation)]
57+
[ABCTestCaseSource2(nameof(ConfigureEngine))]
5458
public void QueryCountry_WithLanguageAndContinentFilters_ShouldReturn200(
55-
string countryCode, string languageCode, string continentCode)
59+
string countryCode, string languageCode, string continentCode)
5660
{
5761
var client = new RestClient("https://countries.trevorblades.com/");
5862
var request = new RestRequest("", Method.Post);

Testimize.Tests/RealWorldExamples/FormValidationTests.cs

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void GenerateTests() =>
175175
settings =>
176176
{
177177
settings.Mode = TestGenerationMode.HybridArtificialBeeColony;
178-
settings.TestCaseCategory = TestCaseCategory.Validation;
178+
settings.TestCaseCategory = TestCaseCategory.Valid;
179179
settings.ABCSettings = new ABCGenerationSettings
180180
{
181181
TotalPopulationGenerations = 100,
@@ -337,5 +337,99 @@ public void SubmitForm_WithValidation(
337337
}
338338
}
339339

340+
[TestCase("Ann", "valid.email+tagging@domain.fr", "+3598888", "Aa1@abcd", 18, "01-01-1990", "http://a.co", true, "United States", new[] { "German" }, "")]
341+
[TestCase("Ann", "valid.email+tagging@domain.fr", "+359888888888", "Aa1@xxxxxxxxxxxxxxxx", 100, "01-01-1920", "http://a.co", true, "Germany", new[] { "German" }, "")]
342+
[TestCase("Ann", "a@e.io", "+3598888", "Aa1@abcd", 18, "01-01-1920", "http://a.co", true, "France", new[] { "English", "French" }, "")]
343+
[TestCase("AAAAAAAAAAAAAAAAAAAA", "valid.email+tagging@domain.fr", "+3598888", "Aa1@abcd", 100, "01-01-1920", "https://example.com", true, "Germany", new[] { "English", "French", "German" }, "")]
344+
[TestCase("Ann", "a@e.io", "+3598888", "Secure1!", 100, "31-12-2020", "http://a.co", true, "United States", new[] { "German" }, "")]
345+
[TestCase("AAAAAAAAAAAAAAAAAAAA", "a@e.io", "+3598888", "Aa1@xxxxxxxxxxxxxxxx", 25, "01-01-1920", "https://very-long-url.com/with/path", true, "Germany", new[] { "English", "French", "German" }, "")]
346+
[TestCase("Ann", "a@e.io", "+359888888888", "Aa1@abcd", 18, "01-01-1920", "https://very-long-url.com/with/path", true, "Germany", new[] { "English", "French", "German" }, "")]
347+
[TestCase("Ann", "valid.email+tagging@domain.fr", "+359888888888", "Aa1@abcd", 18, "01-01-1920", "http://a.co", true, "France", new[] { "English", "French", "German" }, "")]
348+
[TestCase("Ann", "valid.email+tagging@domain.fr", "+3598888", "Aa1@abcd", 18, "01-01-1990", "http://a.co", true, "Germany", new[] { "German" }, "")]
349+
[TestCase("Ann", "valid.email+tagging@domain.fr", "+359888888888888", "Aa1@abcd", 25, "31-12-2020", "http://a.co", true, "United States", new[] { "German" }, "")]
350+
[TestCase("Ann", "a@e.io", "+3598888", "Aa1@abcd", 18, "31-12-2020", "https://very-long-url.com/with/path", true, "Germany", new[] { "English", "French" }, "")]
351+
[TestCase("AAAAAAAAAAAAAAAAAAAA", "a@e.io", "+359888888888", "Aa1@abcd", 18, "01-01-1920", "http://a.co", true, "United States", new[] { "German" }, "")]
352+
[TestCase("Ann", "a@e.io", "+3598888", "Secure1!", 100, "31-12-2020", "https://very-long-url.com/with/path", true, "United States", new[] { "German" }, "")]
353+
[TestCase("Anton Angelov", "a@e.io", "+359888888888888", "Aa1@xxxxxxxxxxxxxxxx", 100, "01-01-1920", "https://very-long-url.com/with/path", true, "France", new[] { "English", "French", "German" }, "")]
354+
[TestCase("Ann", "anton@example.com", "+359888888888888", "Aa1@xxxxxxxxxxxxxxxx", 18, "01-01-1990", "http://a.co", true, "France", new[] { "German" }, "")]
355+
[TestCase("Ann", "a@e.io", "+359888888888888", "Secure1!", 100, "01-01-1920", "https://example.com", true, "Germany", new[] { "English", "French", "German" }, "")]
356+
[TestCase("Ann", "valid.email+tagging@domain.fr", "+3598888", "Secure1!", 25, "01-01-1920", "https://very-long-url.com/with/path", true, "United States", new[] { "English", "French", "German" }, "")]
357+
[TestCase("AAAAAAAAAAAAAAAAAAAA", "anton@example.com", "+359888888888", "Aa1@xxxxxxxxxxxxxxxx", 100, "01-01-1920", "https://very-long-url.com/with/path", true, "France", new[] { "English", "French", "German" }, "")]
358+
[TestCase("AAAAAAAAAAAAAAAAAAAA", "anton@example.com", "+3598888", "Aa1@xxxxxxxxxxxxxxxx", 25, "31-12-2020", "https://very-long-url.com/with/path", true, "United States", new[] { "English", "French", "German" }, "")]
359+
[TestCase("Ann", "valid.email+tagging@domain.fr", "+359888888888888", "Aa1@abcd", 25, "31-12-2020", "https://example.com", true, "France", new[] { "German" }, "")]
360+
[TestCase("Anton Angelov", "a@e.io", "+359888888888888", "Aa1@abcd", 18, "01-01-1990", "http://a.co", true, "Germany", new[] { "English", "French", "German" }, "")]
361+
[TestCase("Ann", "anton@example.com", "+359888888888", "Aa1@abcd", 18, "01-01-1920", "https://very-long-url.com/with/path", true, "United States", new[] { "English", "French", "German" }, "")]
362+
[TestCase("Anton Angelov", "a@e.io", "+359888888888888", "Aa1@abcd", 100, "01-01-1990", "http://a.co", true, "Germany", new[] { "English", "French", "German" }, "")]
363+
[TestCase("Ann", "a@e.io", "+3598888", "Aa1@abcd", 25, "01-01-1990", "http://a.co", true, "Germany", new[] { "German" }, "")]
364+
[TestCase("Ann", "valid.email+tagging@domain.fr", "+359888888888", "Aa1@abcd", 100, "01-01-1920", "https://example.com", true, "United States", new[] { "German" }, "")]
365+
[TestCase("AAAAAAAAAAAAAAAAAAAA", "anton@example.com", "+3598888", "Aa1@abcd", 18, "31-12-2020", "http://a.co", true, "France", new[] { "English", "French" }, "")]
366+
[TestCase("AAAAAAAAAAAAAAAAAAAA", "anton@example.com", "+359888888888888", "Aa1@xxxxxxxxxxxxxxxx", 25, "01-01-1920", "http://a.co", true, "United States", new[] { "German" }, "")]
367+
[TestCase("Ann", "valid.email+tagging@domain.fr", "+359888888888", "Aa1@abcd", 100, "31-12-2020", "https://very-long-url.com/with/path", true, "Germany", new[] { "English", "French" }, "")]
368+
[TestCase("Ann", "a@e.io", "+3598888", "Aa1@abcd", 100, "31-12-2020", "https://example.com", true, "France", new[] { "English", "French" }, "")]
369+
[TestCase("Ann", "a@e.io", "+3598888", "Secure1!", 25, "01-01-1920", "https://very-long-url.com/with/path", true, "Germany", new[] { "German" }, "")]
370+
[TestCase("AAAAAAAAAAAAAAAAAAAA", "a@e.io", "+359888888888", "Aa1@abcd", 18, "01-01-1990", "https://very-long-url.com/with/path", true, "United States", new[] { "German" }, "")]
371+
[Ignore]
372+
public void SuccessMessageDisplayed_WhenSubmitFormWithValidParameters(
373+
string fullName, string email, string phone, string password, int age,
374+
string birthdate, string website, bool? terms, string country, string[] languages, string expectedError)
375+
{
376+
_driver.Navigate().Refresh();
377+
378+
Console.WriteLine("=== Input Parameters ===");
379+
Console.WriteLine($"Full Name: {fullName}");
380+
Console.WriteLine($"Email: {email}");
381+
Console.WriteLine($"Phone: {phone}");
382+
Console.WriteLine($"Password: {password}");
383+
Console.WriteLine($"Age: {age}");
384+
Console.WriteLine($"Birthdate: {birthdate}");
385+
Console.WriteLine($"Website: {website}");
386+
Console.WriteLine($"Terms Accepted: {terms}");
387+
Console.WriteLine($"Country: {country}");
388+
Console.WriteLine($"Languages: {string.Join(", ", languages ?? Array.Empty<string>())}");
389+
Console.WriteLine($"Expected Error: {expectedError}");
390+
391+
_driver.FindElement(By.Id("fullName")).SendKeys(fullName);
392+
_driver.FindElement(By.Id("email")).SendKeys(email);
393+
_driver.FindElement(By.Id("phone")).SendKeys(phone);
394+
_driver.FindElement(By.Id("password")).SendKeys(password);
395+
_driver.FindElement(By.Id("age")).SendKeys(age.ToString());
396+
_driver.FindElement(By.Id("birthdate")).SendKeys(birthdate);
397+
_driver.FindElement(By.Id("website")).SendKeys(website);
398+
if (terms == true) _driver.FindElement(By.Id("terms")).Click();
399+
if (country != null) new SelectElement(_driver.FindElement(By.Id("country"))).SelectByText(country);
400+
401+
if (languages != null)
402+
{
403+
foreach (var l in languages)
404+
{
405+
new SelectElement(_driver.FindElement(By.Id("languages"))).SelectByText(l);
406+
}
407+
}
408+
409+
var submitButton = _driver.FindElement(By.CssSelector("button[type='submit']"));
410+
new Actions(_driver).MoveToElement(submitButton).Click().Perform();
411+
412+
413+
var invalidFeedbackDivs = _driver.FindElements(By.ClassName("invalid-feedback"))
414+
.Where(div => div.Displayed && !string.IsNullOrWhiteSpace(div.Text))
415+
.ToList();
416+
if (invalidFeedbackDivs.Any())
417+
{
418+
Console.WriteLine("=== Displayed Validation Messages ===");
419+
Debug.WriteLine("=== Displayed Validation Messages ===");
420+
foreach (var feedback in invalidFeedbackDivs)
421+
{
422+
Console.WriteLine($"- {feedback.Text}");
423+
Debug.WriteLine($"- {feedback.Text}");
424+
}
425+
426+
Assert.Fail("Expected success message to be visible but there were validation messages displayed.");
427+
}
428+
else
429+
{
430+
var successMsg = _driver.FindElement(By.Id("successMsg"));
431+
Assert.That(successMsg.Displayed, Is.True, "Expected success message to be visible.");
432+
}
433+
}
340434

341435
}

Testimize.Tests/RealWorldExamples/JsonPlaceholderPostTests.cs

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,56 @@
1212
// <author>Anton Angelov</author>
1313
// <site>https://automatetheplanet.com/</site>
1414

15-
using Testimize.Parameters;
1615
using RestSharp;
17-
using System.Collections.Generic;
1816
using System;
17+
using System.Collections.Generic;
1918
using Testimize.Contracts;
20-
using Testimize.OutputGenerators;
2119
using Testimize.Parameters.Core;
20+
using Testimize.OutputGenerators;
21+
using Testimize.Usage;
2222

23-
namespace Testimize.Tests.RealWorld;
23+
namespace Testimize.Tests.RealWorldExamples;
2424

2525
[TestFixture]
2626
public class JsonPlaceholderPostTests
2727
{
28-
//public static List<IInputParameter> ABCGeneratedTestParameters()
29-
//{
30-
// return new List<IInputParameter>
31-
// {
32-
// new TextDataParameter(minBoundary: 5, maxBoundary: 100), // title
33-
// new TextDataParameter(minBoundary: 20, maxBoundary: 500), // body
34-
// new IntegerDataParameter(minBoundary: 1, maxBoundary: 100), // userId
35-
// new UsernameDataParameter(minBoundary: 6, maxBoundary: 15), // authorUsername
36-
// new EmailDataParameter(minBoundary: 10, maxBoundary: 30), // authorEmail
37-
// new BooleanDataParameter(), // isPublished
38-
// new DateTimeDataParameter(minBoundary: DateTime.UtcNow.AddDays(-30), maxBoundary: DateTime.UtcNow) // publishDate
39-
// };
40-
//}
41-
public static List<IInputParameter> ABCGeneratedTestParameters() =>
42-
TestimizeInputBuilder
43-
.Start()
44-
.AddText(5, 100) // title
45-
.AddText(20, 500) // body
46-
.AddInteger(1, 100) // userId
47-
.AddUsername(6, 15) // authorUsername
48-
.AddEmail(10, 30) // authorEmail
49-
.AddBoolean() // isPublished
50-
.AddDateTime(
51-
DateTime.UtcNow.AddDays(-30),
52-
DateTime.UtcNow) // publishDate
53-
.Build();
28+
public static List<TestCase> ConfigureEngine() =>
29+
TestimizeEngine.Configure(
30+
parameters => parameters
31+
.AddText(5, 100) // title
32+
.AddText(20, 500) // body
33+
.AddInteger(1, 100) // userId
34+
.AddUsername(6, 15) // authorUsername
35+
.AddEmail(10, 30) // authorEmail
36+
.AddBoolean() // isPublished
37+
.AddDateTime(
38+
DateTime.UtcNow.AddDays(-30),
39+
DateTime.UtcNow) // publishDate
40+
,
41+
settings =>
42+
{
43+
settings.Mode = TestGenerationMode.HybridArtificialBeeColony;
44+
settings.TestCaseCategory = TestCaseCategory.Validation;
45+
settings.ABCSettings = new ABCGenerationSettings
46+
{
47+
TotalPopulationGenerations = 50,
48+
MutationRate = 0.4,
49+
FinalPopulationSelectionRatio = 0.5,
50+
EliteSelectionRatio = 0.3,
51+
OnlookerSelectionRatio = 0.1,
52+
ScoutSelectionRatio = 0.3,
53+
EnableOnlookerSelection = true,
54+
EnableScoutPhase = true,
55+
EnforceMutationUniqueness = true,
56+
StagnationThresholdPercentage = 0.75,
57+
CoolingRate = 0.95,
58+
AllowMultipleInvalidInputs = false,
59+
OutputGenerator = new NUnitTestCaseAttributeOutputGenerator()
60+
};
61+
}).Generate();
5462

5563
[Test]
56-
[ABCTestCaseSource(nameof(ABCGeneratedTestParameters), TestCaseCategory.Validation)]
64+
[ABCTestCaseSource2(nameof(ConfigureEngine))]
5765
public void CreateFullPost_WithGeneratedMetadata_ShouldSucceed(
5866
string title,
5967
string body,
@@ -86,5 +94,4 @@ public void CreateFullPost_WithGeneratedMetadata_ShouldSucceed(
8694

8795
Assert.That((int)response.StatusCode, Is.EqualTo(201));
8896
}
89-
9097
}

Testimize.Tests/RealWorldExamples/PreciseModeCountriesGraphQLTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
using Testimize.OutputGenerators;
1616
using Testimize.Usage;
1717

18-
namespace Testimize.Tests.RealWorld;
18+
namespace Testimize.Tests.RealWorldExamples;
1919

2020
[TestFixture]
2121
public class PreciseModeCountriesGraphQLTests

Testimize.Tests/RealWorldExamples/ReqresRegistrationTests.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,31 @@
1212
// <author>Anton Angelov</author>
1313
// <site>https://automatetheplanet.com/</site>
1414

15-
using Testimize.Parameters;
16-
using RestSharp;
17-
using System.Collections.Generic;
1815
using System;
19-
using Testimize.Contracts;
16+
using System.Collections.Generic;
17+
using RestSharp;
2018
using Testimize.OutputGenerators;
19+
using Testimize.Parameters.Core;
20+
using Testimize.Usage;
2121

22-
namespace Testimize.Tests.RealWorld;
22+
namespace Testimize.Tests.RealWorldExamples;
2323

2424
[TestFixture]
2525
public class ReqresRegistrationTests
2626
{
27-
public static List<IInputParameter> ABCGeneratedTestParameters()
28-
{
29-
return new List<IInputParameter>
30-
{
31-
new EmailDataParameter(minBoundary: 10, maxBoundary: 20),
32-
new PasswordDataParameter(minBoundary: 8, maxBoundary: 16)
33-
};
34-
}
27+
public static List<TestCase> ConfigureEngine() =>
28+
TestimizeEngine.Configure(
29+
parameters => parameters
30+
.AddEmail(10, 20)
31+
.AddPassword(8, 16),
32+
settings =>
33+
{
34+
settings.Mode = TestGenerationMode.HybridArtificialBeeColony;
35+
settings.TestCaseCategory = TestCaseCategory.Validation;
36+
}).Generate();
3537

3638
[Test]
37-
[ABCTestCaseSource(nameof(ABCGeneratedTestParameters), TestCaseCategory.Validation)]
39+
[ABCTestCaseSource2(nameof(ConfigureEngine))]
3840
public void RegisterUser_WithGeneratedEmailAndPassword(string email, string password)
3941
{
4042
var client = new RestClient("https://reqres.in");
@@ -50,7 +52,9 @@ public void RegisterUser_WithGeneratedEmailAndPassword(string email, string pass
5052
Console.WriteLine($"→ Attempted registration with Email: {email}, Password: {password}");
5153
Console.WriteLine($"← Response: {response.StatusCode}, Content: {response.Content}");
5254

53-
// Expect 200 for known valid email or 400 otherwise (per Reqres.in behavior)
55+
// Reqres returns:
56+
// - 200 when email/password are both valid and known to the system
57+
// - 400 for missing or invalid data
5458
Assert.That((int)response.StatusCode, Is.EqualTo(200).Or.EqualTo(400));
5559
}
5660
}

0 commit comments

Comments
 (0)