Skip to content

Commit

Permalink
Merge pull request #990 from riganti/remove-unnecessary-waits
Browse files Browse the repository at this point in the history
Removing unnecessary waits and waitfor
  • Loading branch information
quigamdev committed May 6, 2021
2 parents a8d9467 + f03c076 commit 0094a5d
Show file tree
Hide file tree
Showing 65 changed files with 489 additions and 815 deletions.
10 changes: 4 additions & 6 deletions src/DotVVM.Samples.Tests/Complex/AuthTests.cs
Expand Up @@ -21,14 +21,12 @@ public void Complex_Auth_Login()
browser.NavigateToUrl(SamplesRouteUrls.ComplexSamples_Auth_Login);
browser.SendKeys("input[type=text]", "user");
browser.First("input[type=button]").Click().Wait(500);
browser.First("input[type=button]").Click();
browser.Refresh();
browser.Wait(2000);
browser.Last("a").Click();
browser.Wait(2000);
browser.SendKeys("input[type=text]", "message");
browser.First("input[type=button]").Click().Wait(500);
browser.First("input[type=button]").Click();
AssertUI.InnerText(browser.ElementAt("h1", 1),
s =>
Expand All @@ -41,11 +39,11 @@ public void Complex_Auth_Login()
browser.ClearElementsContent("input[type=text]");
browser.SendKeys("input[type=text]", "ADMIN");
browser.First("input[type=checkbox]").Click();
browser.First("input[type=button]").Click().Wait(500);
browser.First("input[type=button]").Click();
browser.Last("a").Click();
browser.SendKeys("input[type=text]", "message");
browser.First("input[type=button]").Click().Wait(500);
browser.First("input[type=button]").Click();
AssertUI.InnerText(browser.First("span"), s => s.Contains("ADMIN: message"), "User can't send message");
});
Expand Down
Expand Up @@ -19,9 +19,9 @@ public void Complex_ButtonInMarkupControl_Enabled()
var enabled = browser.Single("enabled", SelectByDataUi);
AssertUI.TextEquals(enabled, "false");
browser.Single("btn-off", SelectByDataUi).Click();
browser.WaitFor(() => AssertUI.TextEquals(enabled, "true"), 1000);
AssertUI.TextEquals(enabled, "true");
browser.Single("btn-on", SelectByDataUi).Click();
browser.WaitFor(() => AssertUI.TextEquals(enabled, "false"), 1000);
AssertUI.TextEquals(enabled, "false");
});
}

Expand Down
25 changes: 17 additions & 8 deletions src/DotVVM.Samples.Tests/Complex/CascadeSelectorsTests.cs
@@ -1,6 +1,7 @@
using DotVVM.Samples.Tests.Base;
using DotVVM.Testing.Abstractions;
using Riganti.Selenium.Core;
using Riganti.Selenium.DotVVM;
using Xunit;

namespace DotVVM.Samples.Tests.Complex
Expand Down Expand Up @@ -29,22 +30,26 @@ public void Complex_CascadeSelectors_TripleComboBoxes()
RunInAllBrowsers(browser =>
{
browser.NavigateToUrl(SamplesRouteUrls.ComplexSamples_CascadeSelectors_TripleComboBoxes);
browser.ElementAt("input[type=button]", 0).Click().Wait();
browser.ElementAt("input[type=button]", 0).Click();
browser.WaitForPostback();
AssertUI.InnerTextEquals(browser.ElementAt(".active", 0), "North America: 1");
AssertUI.InnerTextEquals(browser.ElementAt(".active", 1), "USA: 11");
AssertUI.InnerTextEquals(browser.ElementAt(".active", 2), "New York: 111");
browser.ElementAt("input[type=button]", 2).Click().Wait();
browser.ElementAt("input[type=button]", 2).Click();
browser.WaitForPostback();
AssertUI.InnerTextEquals(browser.ElementAt(".active", 0), "North America: 1");
AssertUI.InnerTextEquals(browser.ElementAt(".active", 1), "Canada: 12");
AssertUI.InnerTextEquals(browser.ElementAt(".active", 2), "Toronto: 121");
browser.ElementAt("input[type=button]", 5).Click().Wait();
browser.ElementAt("input[type=button]", 5).Click();
browser.WaitForPostback();
AssertUI.InnerTextEquals(browser.ElementAt(".active", 0), "Europe: 2");
AssertUI.InnerTextEquals(browser.ElementAt(".active", 1), "Germany: 21");
AssertUI.InnerTextEquals(browser.ElementAt(".active", 2), "Munich: 212");
browser.ElementAt("input[type=button]", 8).Click().Wait();
browser.ElementAt("input[type=button]", 8).Click();
browser.WaitForPostback();
AssertUI.InnerTextEquals(browser.ElementAt(".active", 0), "Asia: 3");
AssertUI.InnerTextEquals(browser.ElementAt(".active", 1), "China: 31");
AssertUI.InnerTextEquals(browser.ElementAt(".active", 2), "Beijing: 311");
Expand All @@ -59,21 +64,25 @@ private void Complex_CascadeSelectorsBase(string url)
// select city
browser.First("select").Select(1);
browser.First("input[type=button]").Click().Wait();
browser.First("input[type=button]").Click();
browser.WaitForPostback();
// select hotel
browser.Last("select").Select(1);
browser.Last("input[type=button]").Click().Wait();
browser.Last("input[type=button]").Click();
browser.WaitForPostback();
AssertUI.InnerTextEquals(browser.First("h2"), "Hotel Seattle #2");
// select city
browser.First("select").Select(0);
browser.First("input[type=button]").Click().Wait();
browser.First("input[type=button]").Click();
browser.WaitForPostback();
// select hotel
browser.Last("select").Select(0);
browser.Last("input[type=button]").Click().Wait();
browser.Last("input[type=button]").Click();
browser.WaitForPostback();
AssertUI.InnerTextEquals(browser.First("h2"), "Hotel Prague #1");
});
Expand Down
65 changes: 16 additions & 49 deletions src/DotVVM.Samples.Tests/Complex/ChangedEventTests.cs
Expand Up @@ -30,14 +30,10 @@ public void Complex_ChangedEvent_ChangedEvent()
AssertUI.InnerTextEquals(totalChanges, "0");
var firstTextbox = browser.First("*[data-id='first-textbox']");
browser.WaitFor(() => {
AssertUI.InnerText(firstTextbox, s => s.Contains("Valuetes"));
}, 4000, 100);
AssertUI.InnerText(firstTextbox, s => s.Contains("Valuetes"));
new Actions(browser.Driver).SendKeys(Keys.Enter).SendKeys(Keys.Tab).Perform();
browser.WaitFor(() => {
AssertUI.InnerTextEquals(firstTextbox, "Valuetest");
}, 4000, 100);
AssertUI.InnerTextEquals(firstTextbox, "Valuetest");
AssertUI.InnerTextEquals(totalChanges, "1");
// second textbox
Expand All @@ -46,16 +42,12 @@ public void Complex_ChangedEvent_ChangedEvent()
textBox2.SetFocus();
new Actions(browser.Driver).SendKeys("test").Perform();
browser.WaitFor(() => {
AssertUI.InnerTextEquals(totalChanges, "1");
}, 4000, 100);
AssertUI.InnerTextEquals(totalChanges, "1");
var secondTextbox = browser.First("*[data-id='second-textbox']");
AssertUI.InnerTextEquals(secondTextbox, "Value");
new Actions(browser.Driver).SendKeys(Keys.Enter).SendKeys(Keys.Tab).Perform();
browser.WaitFor(() => {
AssertUI.InnerTextEquals(secondTextbox, "Valuetest");
}, 4000, 100);
AssertUI.InnerTextEquals(secondTextbox, "Valuetest");
AssertUI.InnerTextEquals(totalChanges, "2");
Expand All @@ -70,72 +62,47 @@ public void Complex_ChangedEvent_ChangedEvent()
new Actions(browser.Driver).SendKeys("c").Perform();
browser.Wait(100);
new Actions(browser.Driver).SendKeys(Keys.Backspace).Perform();
browser.Wait(100);
browser.WaitFor(() => {
AssertUI.InnerTextEquals(totalChanges, "6");
}, 4000, 100);
AssertUI.InnerTextEquals(totalChanges, "6");
var thirdTextBox = browser.First("*[data-id='third-textbox']");
AssertUI.InnerTextEquals(thirdTextBox, "ab");
new Actions(browser.Driver).SendKeys(Keys.Enter).SendKeys(Keys.Tab).Perform();
browser.WaitFor(() => {
AssertUI.InnerTextEquals(thirdTextBox, "ab");
}, 4000, 100);
AssertUI.InnerTextEquals(thirdTextBox, "ab");
AssertUI.InnerTextEquals(totalChanges, "6");
// click on checkbox
browser.Click("input[type=checkbox]");
browser.WaitFor(() => {
AssertUI.InnerTextEquals(totalChanges, "7");
}, 4000, 100);
AssertUI.InnerTextEquals(totalChanges, "7");
browser.Click("input[type=checkbox]");
browser.WaitFor(() => {
AssertUI.InnerTextEquals(totalChanges, "8");
}, 4000, 100);
AssertUI.InnerTextEquals(totalChanges, "8");
// click on radio button
browser.ElementAt("input[type=radio]", 0).Click();
browser.WaitFor(() => {
AssertUI.InnerTextEquals(totalChanges, "9");
}, 4000, 100);
AssertUI.InnerTextEquals(totalChanges, "9");
browser.ElementAt("input[type=radio]", 1).Click();
browser.WaitFor(() => {
AssertUI.InnerTextEquals(totalChanges, "10");
}, 4000, 100);
AssertUI.InnerTextEquals(totalChanges, "10");
browser.ElementAt("input[type=radio]", 2).Click();
browser.WaitFor(() => {
AssertUI.InnerTextEquals(totalChanges, "11");
}, 4000, 100);
AssertUI.InnerTextEquals(totalChanges, "11");
browser.ElementAt("input[type=radio]", 3).Click();
browser.WaitFor(() => {
AssertUI.InnerTextEquals(totalChanges, "12");
}, 4000, 100);
AssertUI.InnerTextEquals(totalChanges, "12");
browser.ElementAt("input[type=radio]", 4).Click();
browser.WaitFor(() => {
AssertUI.InnerTextEquals(totalChanges, "13");
}, 4000, 100);
AssertUI.InnerTextEquals(totalChanges, "13");
// combo box
browser.First("select").Select(1);
browser.WaitFor(() => {
AssertUI.InnerTextEquals(totalChanges, "14");
}, 4000, 100);
AssertUI.InnerTextEquals(totalChanges, "14");
browser.First("select").Select(2);
browser.WaitFor(() => {
AssertUI.InnerTextEquals(totalChanges, "15");
}, 4000, 100);
AssertUI.InnerTextEquals(totalChanges, "15");
browser.First("select").Select(0);
browser.WaitFor(() => {
AssertUI.InnerTextEquals(totalChanges, "16");
}, 4000, 100);
AssertUI.InnerTextEquals(totalChanges, "16");
});
}
Expand Down
10 changes: 4 additions & 6 deletions src/DotVVM.Samples.Tests/Complex/ClassBindingsTests.cs
Expand Up @@ -26,15 +26,13 @@ public void Complex_ClassBindings_AttributeAndPropertyGroup()
var textBox = browser.Single("classes", SelectByDataUi);
textBox.SendKeys("orange");
textBox.SendKeys(Keys.Tab);
browser.WaitFor(() => AssertUI.HasClass(target, "orange"), 2000);
AssertUI.HasClass(target, "orange");
browser.Single("inverted", SelectByDataUi).Click();
browser.Single("border", SelectByDataUi).Click();
browser.WaitFor(() => {
AssertUI.HasClass(target, "orange");
AssertUI.HasClass(target, "inverted");
AssertUI.HasClass(target, "border");
}, 2000);
AssertUI.HasClass(target, "orange");
AssertUI.HasClass(target, "inverted");
AssertUI.HasClass(target, "border");
});
}

Expand Down
1 change: 0 additions & 1 deletion src/DotVVM.Samples.Tests/Complex/DataTemplateTests.cs
Expand Up @@ -13,7 +13,6 @@ public void Complex_EmptyDataTemplate_RepeaterGridView()
{
RunInAllBrowsers(browser => {
browser.NavigateToUrl(SamplesRouteUrls.ComplexSamples_EmptyDataTemplate_RepeaterGridView);
browser.Wait();
void isDisplayed(string id) => AssertUI.IsDisplayed(browser, "#" + id);
void isHidden(string id) => AssertUI.IsNotDisplayed(browser, "#" + id);
void isNotPresent(string id) => browser.FindElements("#" + id + " > *").ThrowIfDifferentCountThan(0);
Expand Down
13 changes: 5 additions & 8 deletions src/DotVVM.Samples.Tests/Complex/InvoiceCalculatorTests.cs
Expand Up @@ -20,32 +20,29 @@ public void Complex_InvoiceCalculator_InvoiceCalculator()
// add lines
addButton.Click();
browser.Wait();
addButton.Click();
browser.Wait();
addButton.Click();
browser.Wait();
// fill second line
var cells = table.ElementAt("tr", 2).FindElements("td");
cells.ElementAt(0).First("input").Clear().SendKeys("111");
cells.ElementAt(1).First("select").Select(1).Wait();
cells.ElementAt(1).First("select").Select(1);
cells.ElementAt(2).First("input").Clear().SendKeys("Bread");
cells.ElementAt(3).First("input").Clear().SendKeys("12");
cells.ElementAt(4).First("input").Clear().SendKeys("10");
// fill third line
cells = table.ElementAt("tr", 3).FindElements("td");
cells.ElementAt(0).First("input").Clear().SendKeys("222");
cells.ElementAt(1).First("select").Select(2).Wait();
cells.ElementAt(1).First("select").Select(2);
cells.ElementAt(2).First("input").Clear().SendKeys("Ham");
cells.ElementAt(3).First("input").Clear().SendKeys("1");
cells.ElementAt(4).First("input").Clear().SendKeys("5");
// fill fourth line
cells = table.ElementAt("tr", 4).FindElements("td");
cells.ElementAt(0).First("input").Clear().SendKeys("333");
cells.ElementAt(1).First("select").Select(3).Wait();
cells.ElementAt(1).First("select").Select(3);
cells.ElementAt(2).First("input").Clear().SendKeys("Cheese");
cells.ElementAt(3).First("input").Clear().SendKeys("10");
cells.ElementAt(4).First("input").Clear().SendKeys("15");
Expand All @@ -58,13 +55,13 @@ public void Complex_InvoiceCalculator_InvoiceCalculator()
AssertUI.InnerTextEquals(table.ElementAt("tr", 4).ElementAt("td", 5), "180");
// recalculate
recalculateButton.Click().Wait();
recalculateButton.Click();
// verify total price
AssertUI.InnerTextEquals(table.Last("tr").ElementAt("th", 1), "407.5");
// remove second line
table.ElementAt("tr", 2).Last("td").First("a").Click().Wait();
table.ElementAt("tr", 2).Last("td").First("a").Click();
// verify total price
AssertUI.InnerTextEquals(table.Last("tr").ElementAt("th", 1), "281.5");
Expand Down
4 changes: 2 additions & 2 deletions src/DotVVM.Samples.Tests/Complex/NestedComboBoxTests.cs
Expand Up @@ -30,10 +30,10 @@ public void Complex_NestedComboBox_HeavilyNested()
var combobox = browser.Single("combobox", SelectByDataUi);
combobox.Select(1);
browser.WaitFor(() => AssertUI.TextEquals(selectedValue, "2"), 1000);
AssertUI.TextEquals(selectedValue, "2");
combobox.Select(0);
browser.WaitFor(() => AssertUI.TextEquals(selectedValue, ""), 1000);
AssertUI.TextEquals(selectedValue, "");
});
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/DotVVM.Samples.Tests/Complex/RedirectAndUrlTests.cs
Expand Up @@ -3,6 +3,7 @@
using Riganti.Selenium.Core;
using Riganti.Selenium.Core.Abstractions;
using Riganti.Selenium.Core.Abstractions.Exceptions;
using Riganti.Selenium.DotVVM;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -21,14 +22,12 @@ public void Complex_RedirectAndUrl_PostbackInteruption()
//Postback with no redirect sets message
browser.NavigateToUrl(SamplesRouteUrls.ComplexSamples_RedirectAndUrl_ScrollingPage);
browser.First("a[data-ui=test-link]").Click();
browser.Wait(200);
AssertUI.InnerTextEquals(browser.First("span[data-ui='message1']"), "TestMessage");
//used RedirectToUrl to redirect to page with Id, however the redirect made page reload and discarted the viewmodel
//therefore message1 should be blank
//view should scroll to #paragraph2
browser.First("a[data-ui='go-to-2-url-link']").Click();
browser.Wait(1200);
// message 2 should be scrolled to message 1 should not, both should be blank
var message2element = browser.First("span[data-ui='message2']");
message2element.IsDisplayed();
Expand All @@ -53,12 +52,10 @@ public void Complex_RedirectAndUrl_ScrollingPage()
//Postback with no redirect sets message to 'TestMessage'
browser.NavigateToUrl(SamplesRouteUrls.ComplexSamples_RedirectAndUrl_ScrollingPage);
browser.First("a[data-ui=test-link]").Click();
browser.Wait(200);
AssertUI.InnerText(browser.First("span[data-ui='message1']"), s => s.Equals("TestMessage"));
//Postback should run and view should scroll, page should not reload therefore messeges remain.
browser.First("a[data-ui='go-to-2-link']").Click();
browser.Wait(200);
var message2element = browser.First("span[data-ui='message2']");
var message1element = browser.First("span[data-ui='message1']");
Expand All @@ -75,7 +72,6 @@ public void Complex_RedirectAndUrl_ScrollingPage()
//basically the same just clicking on link to do postback and scroll back to paragraph1 after
browser.First("a[data-ui='go-to-1-link']").Click();
browser.Wait(200);
// message 2 should be scrolled to message 1 should not, both should be blank
message2element.IsDisplayed();
Expand All @@ -95,6 +91,7 @@ public void Complex_RedirectAndUrl_ScrollingPage()
message2element.CheckIfIsElementInView();
goTo1Link.Click();
browser.WaitForPostback();
message1element.CheckIfIsElementInView();
message2element.CheckIfIsElementNotInView();
});
Expand Down
2 changes: 2 additions & 0 deletions src/DotVVM.Samples.Tests/Complex/SPAErrorReportingTests.cs
Expand Up @@ -6,6 +6,7 @@
using OpenQA.Selenium.Chrome;
using Riganti.Selenium.Core;
using Riganti.Selenium.Core.Abstractions.Attributes;
using Riganti.Selenium.DotVVM;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -45,6 +46,7 @@ void SetOfflineMode(bool offline)
// go to Test page and verify the success
browser.ElementAt("a", 1).Click();
browser.WaitForPostback();
AssertUI.TextEquals(browser.Single("h2"), "Test");
SetOfflineMode(true);
Expand Down

0 comments on commit 0094a5d

Please sign in to comment.