Selenium Tests - start backup
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Drivers\" />
|
||||
<Folder Include="test-backup-source\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Duplicati.Browser.Test.Hooks
|
||||
public static void BeforeScenario(BrowserDriver browserDriver)
|
||||
{
|
||||
var calculatorPageObject = new DuplicatiPageObject(browserDriver.Current);
|
||||
calculatorPageObject.EnsureCalculatorIsOpenAndReset();
|
||||
calculatorPageObject.Open();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,10 +137,12 @@ public class ScheduleSettingsPage(IWebDriver webDriver)
|
||||
public class ToOptionsSettingsPage(IWebDriver webDriver)
|
||||
{
|
||||
private IWebElement SaveButtonElement => webDriver.WaitForElement(By.CssSelector("#save"));
|
||||
private IWebElement ConfirmationModal => webDriver.WaitForElement(By.CssSelector(".content.buttons"));
|
||||
|
||||
public ToOptionsSettingsPage Save()
|
||||
{
|
||||
SaveButtonElement.Click();
|
||||
ConfirmationModal.WaitForElement(By.CssSelector("ul>li:nth-child(2)>a")).Click();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -13,16 +13,10 @@ namespace Duplicati.Browser.Test.PageObjects
|
||||
//The URL of the calculator to be opened in the browser
|
||||
private const string DuplicatiUrl = "http://localhost:8201";
|
||||
|
||||
//The Selenium web driver to automate the browser
|
||||
|
||||
//The default wait time in seconds for wait.Until
|
||||
public const int DefaultWaitInSeconds = 5;
|
||||
|
||||
//Finding elements by ID
|
||||
private IWebElement AddBackupElement => webDriver.WaitForElement(By.ClassName("add"));
|
||||
private IWebElement AddButtonElement => webDriver.WaitForElement(By.Id("add-button"));
|
||||
private IWebElement ResultElement => webDriver.WaitForElement(By.Id("result"));
|
||||
private IWebElement ResetButtonElement => webDriver.WaitForElement(By.Id("reset-button"));
|
||||
private IWebElement HomeButtonElement => webDriver.WaitForElement(By.ClassName("home"));
|
||||
private IWebElement BackupSection => webDriver.WaitForElement(By.ClassName("task"));
|
||||
|
||||
public AddBackupPage NavigateToBackupCreation()
|
||||
{
|
||||
@@ -30,65 +24,21 @@ namespace Duplicati.Browser.Test.PageObjects
|
||||
return new AddBackupPage(webDriver);
|
||||
}
|
||||
|
||||
public void ClickAdd()
|
||||
public void StartBackupTask()
|
||||
{
|
||||
//Click the add button
|
||||
AddButtonElement.Click();
|
||||
//Navigate to home just in case
|
||||
HomeButtonElement.Click();
|
||||
BackupSection.WaitForElement(By.ClassName("ng-binding")).Click();
|
||||
BackupSection.WaitForElement(By.XPath("/dl[1]/dd[1]/p[1]"));
|
||||
}
|
||||
|
||||
public void EnsureCalculatorIsOpenAndReset()
|
||||
public void Open()
|
||||
{
|
||||
//Open the calculator page in the browser if not opened yet
|
||||
if (webDriver.Url != DuplicatiUrl)
|
||||
{
|
||||
webDriver.Url = DuplicatiUrl;
|
||||
}
|
||||
//Otherwise reset the calculator by clicking the reset button
|
||||
else
|
||||
{
|
||||
//Click the rest button
|
||||
ResetButtonElement.Click();
|
||||
|
||||
//Wait until the result is empty again
|
||||
WaitForEmptyResult();
|
||||
}
|
||||
}
|
||||
|
||||
public string WaitForNonEmptyResult()
|
||||
{
|
||||
//Wait for the result to be not empty
|
||||
return WaitUntil(
|
||||
() => ResultElement.GetAttribute("value"),
|
||||
result => !string.IsNullOrEmpty(result));
|
||||
}
|
||||
|
||||
public string WaitForEmptyResult()
|
||||
{
|
||||
//Wait for the result to be empty
|
||||
return WaitUntil(
|
||||
() => ResultElement.GetAttribute("value"),
|
||||
result => result == string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to wait until the expected result is available on the UI
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of result to retrieve</typeparam>
|
||||
/// <param name="getResult">The function to poll the result from the UI</param>
|
||||
/// <param name="isResultAccepted">The function to decide if the polled result is accepted</param>
|
||||
/// <returns>An accepted result returned from the UI. If the UI does not return an accepted result within the timeout an exception is thrown.</returns>
|
||||
private T WaitUntil<T>(Func<T> getResult, Func<T, bool> isResultAccepted) where T: class
|
||||
{
|
||||
var wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(DefaultWaitInSeconds));
|
||||
return wait.Until(driver =>
|
||||
{
|
||||
var result = getResult();
|
||||
if (!isResultAccepted(result))
|
||||
return default;
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,16 +38,16 @@ namespace Duplicati.Browser.Test.Steps
|
||||
public void WhenBackupIsRun()
|
||||
{
|
||||
//delegate to Page Object
|
||||
_duplicatiPageObject.ClickAdd();
|
||||
_duplicatiPageObject.StartBackupTask();
|
||||
}
|
||||
|
||||
[Then("the result should be (.*)")]
|
||||
public void ThenTheResultShouldBe(int expectedResult)
|
||||
{
|
||||
//delegate to Page Object
|
||||
var actualResult = _duplicatiPageObject.WaitForNonEmptyResult();
|
||||
//var actualResult = _duplicatiPageObject.WaitForNonEmptyResult();
|
||||
|
||||
actualResult.Should().Be(expectedResult.ToString());
|
||||
//actualResult.Should().Be(expectedResult.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user