Skip to content

Commit

Permalink
Merge pull request #1494 from riganti/fix-ci-warnings
Browse files Browse the repository at this point in the history
 Fix warnings in the test project
  • Loading branch information
exyi authored Nov 2, 2022
2 parents f4fc7e5 + ea2af16 commit 2cc6b81
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .github/uitest/uitest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function Publish-Sample {
"-p:PublishProfile=$root\.github\uitest\GenericPublish.pubxml", `
"-p:DeployOnBuild=true", `
"-p:Configuration=$config", `
"-p:WarningLevel=0", `
"-p:SourceLinkCreate=true"
Wait-Process -InputObject $msBuildProcess
if ($msBuildProcess.ExitCode -ne 0) {
Expand Down Expand Up @@ -192,6 +193,7 @@ try {
"--no-restore", `
"--logger", `
"trx;LogFileName=$TrxName", `
"-p:WarningLevel=0", `
"--results-directory", `
"$testResultsDir"
Wait-Process -InputObject $uiTestProcess
Expand Down
1 change: 1 addition & 0 deletions .github/uitest/uitest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ function start_samples {
PORT=$2
PID_VAR=$3
dotnet run --project "$ROOT/${PROJECT}" \
-p:WarningLevel=0 \
--no-restore \
--configuration "$CONFIGURATION" \
-- \
Expand Down
2 changes: 1 addition & 1 deletion src/Samples/Tests/Tests/Control/CheckBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void Control_CheckBox_CheckBoxObjects()
AssertUI.TextEquals(ul.ElementAt("li", 1), "3: Blue");

// click button
browser.Single("input[type=button]").Click().Wait();
browser.Single("input[type=button]").Click();
AssertUI.IsNotChecked(checkboxes[0]);
AssertUI.IsChecked(checkboxes[1]);
AssertUI.IsNotChecked(checkboxes[2]);
Expand Down
5 changes: 5 additions & 0 deletions src/Samples/Tests/Tests/ErrorsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Xunit.Abstractions;
using Riganti.Selenium.DotVVM;
using OpenQA.Selenium;
using System.Net.Http;

namespace DotVVM.Samples.Tests
{
Expand Down Expand Up @@ -313,7 +314,9 @@ public void Error_ExceptionWindow_DotNetReferenceSourceRedirect()
var query = link.Substring(startQuery + 2);
//Log("query: " + query);
var specificLink = "https://referencesource.microsoft.com/api/symbols/?symbol=" + query;
#pragma warning disable SYSLIB0014 // obsolete warning, they can't remove this anyway :)
using (var wc = new System.Net.WebClient())
#pragma warning restore SYSLIB0014
{
var downloadedString = wc.DownloadString(specificLink);
if (downloadedString.IndexOf("No results found", StringComparison.OrdinalIgnoreCase) != -1)
Expand Down Expand Up @@ -364,7 +367,9 @@ public void Error_ExceptionWindow_GitHubRedirect()
var link = browser.FindElements("div.exceptionStackTrace span.docLinks a")
.First(s => s.Children.Any(c => c.GetTagName() == "img" && ((c.GetAttribute("src")?.IndexOf("github", StringComparison.OrdinalIgnoreCase) ?? -1) > -1)))
.GetAttribute("href");
#pragma warning disable SYSLIB0014 // obsolete warning
var wr = (System.Net.HttpWebRequest)System.Net.WebRequest.CreateHttp(link);
#pragma warning restore SYSLIB0014

using (var response = wr.GetResponse())
{
Expand Down
44 changes: 24 additions & 20 deletions src/Samples/Tests/Tests/Feature/ApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Riganti.Selenium.DotVVM;
using Xunit;
using Xunit.Abstractions;
using static DotVVM.Samples.Tests.UITestUtils;

namespace DotVVM.Samples.Tests.Feature
{
Expand All @@ -24,43 +25,46 @@ public void Feature_Api_GetCollection()

// click the first button (ID = 11)
browser.WaitFor(() => {
browser.First(".id-company[data-company-id='11'] input[type=button]").Click()
.Wait();
browser.First(".id-company[data-company-id='11'] input[type=button]").Click();
}, 30000, "Cannot find CompanyID = 11. Probably data are not loaded. (The page did not load in 5s.)");

// ensure that orders have been loaded
var orders = browser.FindElements(".id-order");
AssertUI.Any(orders).Attribute("data-order-id", "6");
WaitForIgnoringStaleElements(() => {
AssertUI.Any(browser.FindElements(".id-order"), waitForOptions: WaitForOptions.Disabled).Attribute("data-order-id", "6");
});

var idToDelete = orders[2].GetAttribute("data-order-id"); // every order has two elements (read-only and edit)
var idToDelete = browser.FindElements(".id-order")[2].GetAttribute("data-order-id"); // every order has two elements (read-only and edit)

// delete order (ID = 7)
browser.First($".id-order[data-order-id='{idToDelete}'] input[type=button][value=Delete]").Click().Wait();
orders = browser.FindElements(".id-order");
AssertUI.Any(orders).Attribute("data-order-id", "6");
AssertUI.All(orders).Attribute("data-order-id", s => s != idToDelete);
browser.First($".id-order[data-order-id='{idToDelete}'] input[type=button][value=Delete]").Click();
WaitForIgnoringStaleElements(() => {
AssertUI.Any(browser.FindElements(".id-order"), WaitForOptions.Disabled).Attribute("data-order-id", "6");
AssertUI.All(browser.FindElements(".id-order"), WaitForOptions.Disabled).Attribute("data-order-id", s => s != idToDelete);
});

// click the second button (ID = 12)
browser.First(".id-company[data-company-id='12'] input[type=button]").Click().Wait();
browser.First(".id-company[data-company-id='12'] input[type=button]").Click();


// ensure that orders have been loaded
orders = browser.FindElements(".id-order");
AssertUI.Any(orders).Attribute("data-order-id", "2");
AssertUI.Any(orders).Attribute("data-order-id", "9");
WaitForIgnoringStaleElements(() => {
AssertUI.Any(browser.FindElements(".id-order"), WaitForOptions.Disabled).Attribute("data-order-id", "2");
AssertUI.Any(browser.FindElements(".id-order"), WaitForOptions.Disabled).Attribute("data-order-id", "9");
});

// edit order (ID = 2)
browser.First(".id-order[data-order-id='2'] input[type=button][value=Edit]").Click().Wait();
browser.First(".id-order[data-order-id='2'] input[type=button][value=Edit]").Click();
browser.First(".id-order.id-edit input[type=text]").Clear().SendKeys("2000-01-01");
browser.First(".id-order.id-edit input[type=button][value=Apply]").Click().Wait();
browser.First(".id-order.id-edit input[type=button][value=Exit]").Click().Wait();
browser.First(".id-order.id-edit input[type=button][value=Apply]").Click();
browser.First(".id-order.id-edit input[type=button][value=Exit]").Click();

AssertUI.TextEquals(browser.First(".id-order[data-order-id='2'] .id-date"), "2000-01-01");

// change the order (ID = 2) date back so the test can be run once again
browser.First(".id-order[data-order-id='2'] input[type=button][value=Edit]").Click().Wait();
browser.First(".id-order[data-order-id='2'] input[type=button][value=Edit]").Click();
browser.First(".id-order.id-edit input[type=text]").Clear().SendKeys("2010-01-01");
browser.First(".id-order.id-edit input[type=button][value=Apply]").Click().Wait();
browser.First(".id-order.id-edit input[type=button][value=Exit]").Click().Wait();
browser.First(".id-order.id-edit input[type=button][value=Apply]").Click();
browser.First(".id-order.id-edit input[type=button][value=Exit]").Click();

AssertUI.TextEquals(browser.First(".id-order[data-order-id='2'] .id-date"), "2010-01-01");
});
Expand Down Expand Up @@ -147,7 +151,7 @@ public void Feature_Api_AzureFunctionsApiTable()
{
r.First("input[type=checkbox]").Click();
}
browser.First(".form-grid input[type=button]").Click().Wait();
browser.First(".form-grid input[type=button]").Click();
browser.ElementAt(".form-create input[type=button]", 1).Click();

// make sure it disappeared
Expand Down
8 changes: 6 additions & 2 deletions src/Samples/Tests/Tests/Feature/DictionaryTranslationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Riganti.Selenium.DotVVM;
using Xunit;
using Xunit.Abstractions;
using static DotVVM.Samples.Tests.UITestUtils;

namespace DotVVM.Samples.Tests.Feature
{
Expand All @@ -24,8 +25,11 @@ public void Feature_DictionaryTranslation_Clear()
inputs.ElementAt(4).Click();

WaitForExecutor.WaitFor(() => {
AssertUI.Text(browser.ElementAt("span", 0), s => !s.Contains("KEY: "), waitForOptions: WaitForOptions.Disabled);
AssertUI.Text(browser.ElementAt("span", 1), s => !s.Contains("VAL: "), waitForOptions: WaitForOptions.Disabled);
StaleElementRetry(() => {
AssertUI.Text(browser.ElementAt("span", 0), s => !s.Contains("KEY: "), waitForOptions: WaitForOptions.Disabled);
AssertUI.Text(browser.ElementAt("span", 1), s => !s.Contains("VAL: "), waitForOptions: WaitForOptions.Disabled);
});

}, options: WaitForOptions.LongerTimeout);

});
Expand Down
2 changes: 2 additions & 0 deletions src/Samples/Tests/Tests/Feature/ReturnedFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ private void ReturnedFileDownload(IBrowserWrapper browser, string fileContent)
Assert.NotEmpty(downloadURL);

string returnedFile;
#pragma warning disable SYSLIB0014 // obsolete
using (var client = new WebClient())
#pragma warning restore SYSLIB0014
{
returnedFile = client.DownloadString(browser.GetAbsoluteUrl(downloadURL));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Samples/Tests/Tests/SpaNavigationToEmptyUrlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void SpaNavigationToEmptyUrlTest()
RunInAllBrowsers(browser => {
browser.NavigateToUrl(SamplesRouteUrls.SpaNavigationToEmptyUrl);

browser.Single("a").Click().Wait();
browser.Single("a").Click();

AssertUI.UrlEquals(browser, browser.BaseUrl);
});
Expand All @@ -33,7 +33,7 @@ public void SpaNavigationToEmptyUrlTest_Redirect()
RunInAllBrowsers(browser => {
browser.NavigateToUrl(SamplesRouteUrls.SpaNavigationToEmptyUrl);

browser.Single("input[type=button]").Click().Wait();
browser.Single("input[type=button]").Click();

AssertUI.UrlEquals(browser, browser.BaseUrl);
});
Expand Down
31 changes: 31 additions & 0 deletions src/Samples/Tests/Tests/UITestUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using OpenQA.Selenium;
using Riganti.Selenium.Core;

namespace DotVVM.Samples.Tests;
public static class UITestUtils
{

public static T StaleElementRetry<T>(Func<T> action, int attempts = 5)
{
if (attempts <= 0)
return action();

try
{
return action();
}
catch (StaleElementReferenceException)
{
return StaleElementRetry<T>(action, attempts - 1);
}
}
public static void StaleElementRetry(Action action, int attempts = 5) =>
StaleElementRetry(() => { action(); return 0; }, attempts);


public static void WaitForIgnoringStaleElements(Action action, WaitForOptions options = null)
{
WaitForExecutor.WaitFor(() => StaleElementRetry(action), options);
}
}

0 comments on commit 2cc6b81

Please sign in to comment.