From b29b560b14b64e4ad5f76cdffb27f7d312167ec7 Mon Sep 17 00:00:00 2001 From: kayone Date: Sun, 17 Nov 2013 19:34:31 -0800 Subject: [PATCH] new add series page automation PageBase helper class. --- .../AutomationTest.cs | 7 +- src/NzbDrone.Automation.Test/MainPagesTest.cs | 55 ++++++++-- .../NzbDrone.Automation.Test.csproj | 3 +- .../PageModel/PageBase.cs | 100 ++++++++++++++++++ 4 files changed, 150 insertions(+), 15 deletions(-) create mode 100644 src/NzbDrone.Automation.Test/PageModel/PageBase.cs diff --git a/src/NzbDrone.Automation.Test/AutomationTest.cs b/src/NzbDrone.Automation.Test/AutomationTest.cs index 5fbbf4144..0f1fd5742 100644 --- a/src/NzbDrone.Automation.Test/AutomationTest.cs +++ b/src/NzbDrone.Automation.Test/AutomationTest.cs @@ -7,6 +7,7 @@ using NLog; using NLog.Config; using NLog.Targets; using NUnit.Framework; +using NzbDrone.Automation.Test.PageModel; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Test.Common; using OpenQA.Selenium; @@ -46,9 +47,8 @@ namespace NzbDrone.Automation.Test driver.Url = "http://localhost:8989"; - var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); - - wait.Until(d => d.FindElement(By.Id("x-toolbar"))); + var page = new PageBase(driver); + page.WaitForNoSpinner(); GetPageErrors().Should().BeEmpty(); @@ -70,7 +70,6 @@ namespace NzbDrone.Automation.Test [TearDown] public void AutomationTearDown() { - Thread.Sleep(2000); GetPageErrors().Should().BeEmpty(); } } diff --git a/src/NzbDrone.Automation.Test/MainPagesTest.cs b/src/NzbDrone.Automation.Test/MainPagesTest.cs index 0d583f27d..0b20f3c35 100644 --- a/src/NzbDrone.Automation.Test/MainPagesTest.cs +++ b/src/NzbDrone.Automation.Test/MainPagesTest.cs @@ -1,44 +1,79 @@ using FluentAssertions; using NUnit.Framework; +using NzbDrone.Automation.Test.PageModel; +using OpenQA.Selenium; namespace NzbDrone.Automation.Test { [TestFixture] public class MainPagesTest : AutomationTest { + private PageBase page; + + + [SetUp] + public void Setup() + { + page = new PageBase(driver); + } + + [Test] public void series_page() { - driver.FindElementByLinkText("Series").Click(); - driver.FindElementByClassName("iv-series-index-seriesindexlayout").Should().NotBeNull(); + page.SeriesNavIcon.Click(); + page.WaitForNoSpinner(); + page.FindByClass("iv-series-index-seriesindexlayout").Should().NotBeNull(); } [Test] public void calendar_page() { - driver.FindElementByLinkText("Calendar").Click(); - driver.FindElementByClassName("iv-calendar-calendarlayout").Should().NotBeNull(); + page.CalendarNavIcon.Click(); + page.WaitForNoSpinner(); + + page.FindByClass("iv-calendar-calendarlayout").Should().NotBeNull(); } [Test] public void history_page() { - driver.FindElementByLinkText("History").Click(); - driver.FindElementByClassName("iv-history-historylayout").Should().NotBeNull(); + page.HistoryNavIcon.Click(); + page.WaitForNoSpinner(); + + page.FindByClass("iv-history-historylayout").Should().NotBeNull(); } [Test] public void missing_page() { - driver.FindElementByLinkText("Settings").Click(); - + page.MissingNavIcon.Click(); + page.WaitForNoSpinner(); + + page.FindByClass("iv-missing-missinglayout").Should().NotBeNull(); } [Test] public void system_page() { - driver.FindElementByLinkText("System").Click(); - driver.FindElementByClassName("iv-system-systemlayout").Should().NotBeNull(); + page.SystemNavIcon.Click(); + page.WaitForNoSpinner(); + + page.FindByClass("iv-system-systemlayout").Should().NotBeNull(); + } + + + [Test] + public void add_series_page() + { + page.SeriesNavIcon.Click(); + page.WaitForNoSpinner(); + + page.Find(By.LinkText("Add Series")).Click(); + + page.WaitForNoSpinner(); + + page.FindByClass("iv-addseries-addserieslayout").Should().NotBeNull(); } diff --git a/src/NzbDrone.Automation.Test/NzbDrone.Automation.Test.csproj b/src/NzbDrone.Automation.Test/NzbDrone.Automation.Test.csproj index 26fc816fa..e310da757 100644 --- a/src/NzbDrone.Automation.Test/NzbDrone.Automation.Test.csproj +++ b/src/NzbDrone.Automation.Test/NzbDrone.Automation.Test.csproj @@ -1,5 +1,5 @@  - + Debug @@ -62,6 +62,7 @@ + diff --git a/src/NzbDrone.Automation.Test/PageModel/PageBase.cs b/src/NzbDrone.Automation.Test/PageModel/PageBase.cs new file mode 100644 index 000000000..3ed74c8fb --- /dev/null +++ b/src/NzbDrone.Automation.Test/PageModel/PageBase.cs @@ -0,0 +1,100 @@ +using System; +using System.Threading; +using OpenQA.Selenium; +using OpenQA.Selenium.Remote; +using OpenQA.Selenium.Support.UI; + +namespace NzbDrone.Automation.Test.PageModel +{ + public class PageBase + { + private readonly RemoteWebDriver _driver; + + public PageBase(RemoteWebDriver driver) + { + _driver = driver; + } + + public IWebElement FindByClass(string className, int timeout = 5) + { + return Find(By.ClassName(className), timeout); + } + + public IWebElement Find(By by, int timeout = 5) + { + var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(timeout)); + return wait.Until(d => d.FindElement(by)); + } + + + public void WaitForNoSpinner(int timeout = 20) + { + //give the spinner some time to show up. + Thread.Sleep(100); + + var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(timeout)); + wait.Until(d => + { + try + { + IWebElement element = d.FindElement(By.Id("followingBalls")); + return !element.Displayed; + } + catch (NoSuchElementException) + { + return true; + } + }); + } + + + public IWebElement SeriesNavIcon + { + get + { + return Find(By.LinkText("Series")); + } + } + + public IWebElement CalendarNavIcon + { + get + { + return Find(By.LinkText("Calendar")); + } + } + + public IWebElement HistoryNavIcon + { + get + { + return Find(By.LinkText("History")); + } + } + + public IWebElement MissingNavIcon + { + get + { + return Find(By.LinkText("Missing")); + } + } + + public IWebElement SettingNavIcon + { + get + { + return Find(By.LinkText("Settings")); + } + } + + public IWebElement SystemNavIcon + { + get + { + return Find(By.LinkText("System")); + } + } + + } +} \ No newline at end of file