コード例 #1
0
        protected void LoginIfNeeded(string userName, string password)
        {
            if (!this.IsLoggedIn())
            {
                this.Driver.Navigate().GoToUrl(this.GetAbsoluteUrl("Account/Login"));
            }

            if (this.Driver.Url.IndexOf("Login", StringComparison.InvariantCultureIgnoreCase) != -1 &&

                this.Driver.FindElement(By.Id(Strings.Id.LoginForm)) != null)
            {
                IntegrationTestBase.Log("Trying to log in...");
                IWebElement login = this.Driver.FindElement(By.Id(Strings.Id.Email));

                if (login != null)
                {
                    IWebElement pass = this.Driver.FindElement(By.Id(Strings.Id.Password));
                    login.SendKeys(userName);
                    pass.SendKeys(password);
                    IWebElement submit = this.Driver.FindElement(By.Id(Strings.Id.SubmitLogin));
                    submit.ClickWrapper(this.Driver);
                    this.GoToAdminHomePage();
                    this.RecognizeAdminDashboardPage();
                }
            }
            else
            {
                IntegrationTestBase.Log("Skipping logging in");
            }
        }
コード例 #2
0
        private void DownloadAndInstallMsiProgramPackage(string appName, string packageFileName, [CallerMemberName] string caller = null)
        {
            try
            {
                this.LoginAdminIfNeeded();

                WebDriverWait wait = new WebDriverWait(this.Driver, TimeSpan.FromSeconds(15));

                this.ClickOnManageProgramMenu(appName);

                IWebElement link = wait.Until(ExpectedConditions.ElementIsVisible(By.Id(Strings.Id.DownloadProgramLink)));



                IntegrationTestBase.Log($"Clicking on download URL to store file in {DownloadPath}");

                FileInfo file = this.ActAndWaitForFileDownload(() => link.ClickWrapper(this.Driver), packageFileName, TimeSpan.FromSeconds(80)
                                                               , DownloadPath);

                IntegrationTestBase.Log($"File downloaded {file.FullName}. ");

                this.InstallMsi3AndVerify(file);

                IntegrationTestBase.Log($"Deleting downloaded file {file.FullName}. ");

                file.Delete();
            }
            catch (Exception ex)
            {
                this.HandleError(ex, caller);
            }
        }
コード例 #3
0
        protected IWebElement TryFindAppMenu(string appName)
        {
            WebDriverWait wait    = new WebDriverWait(this.Driver, TimeSpan.FromSeconds(15));
            IWebElement   element = this.Driver.TryFind(By.Id($"{appName}_menu"));

            if (element == null || !element.Displayed)
            {
                var devTeamElement = this.Driver.TryFind(By.Id($"{Strings.Id.AppsList}_TelimenaSystemDevTeam"));
                wait.Until(ExpectedConditions.ElementToBeClickable(devTeamElement));
                devTeamElement.ClickWrapper(this.Driver);
                IntegrationTestBase.Log($"{appName}_menu was not visible. Clicked on team node to expand.");
            }

            element = this.Driver.TryFind(By.Id($"{appName}_menu"));
            if (element != null)
            {
                IntegrationTestBase.Log($"Found {appName}_menu button");
            }
            else
            {
                IntegrationTestBase.Log($"Did not find {appName}_menu button");
            }

            return(element);
        }
コード例 #4
0
        private void ValidateSequencePage(IWebElement table, WebDriverWait wait)
        {
            Retrier.RetryAsync(() =>
            {
                table    = wait.Until(ExpectedConditions.ElementIsVisible(By.Id(Strings.Id.ViewUsageTable)));
                var elms = table.FindElements(By.TagName("tr"));
                IntegrationTestBase.Log($"View usage table row count: {elms.Count}");
                Assert.IsTrue(elms.Count > 1, "View usage table does not have at least one row");
            }, TimeSpan.FromMilliseconds(1000), 30).GetAwaiter().GetResult();

            var rows = table.FindElements(By.TagName("tr"));

            if (rows.Count > 1)
            {
                var cells = rows[1].FindElements(By.TagName("td"));

                var link = cells[1].FindElement(By.TagName("a"));

                link.ClickWrapper(this.Driver);

                Retrier.RetryAsync(() =>
                {
                    var sequenceTable = wait.Until(ExpectedConditions.ElementIsVisible(By.Id(Strings.Id.SequenceHistoryTable)));
                    var sequenceRows  = sequenceTable.FindElements(By.TagName("tr"));
                    Assert.IsTrue(sequenceRows.Count > 1, $"Sequence table does not contain sequence elements. [{sequenceTable.Text}]"); //includes header
                }, TimeSpan.FromMilliseconds(1000), 30).GetAwaiter().GetResult();
            }
        }
コード例 #5
0
        protected void ClickOnProgramMenuButton(string appName, string buttonSuffix)
        {
            try
            {
                Retrier.RetryAsync(() =>
                {
                    WebDriverWait wait  = new WebDriverWait(this.Driver, TimeSpan.FromSeconds(15));
                    IWebElement element = this.Driver.TryFind(By.Id($"{appName}_menu"));

                    IntegrationTestBase.Log($"Found { appName}_menu button");

                    var prgMenu = wait.Until(ExpectedConditions.ElementToBeClickable(element));
                    prgMenu.ClickWrapper(this.Driver);
                    IntegrationTestBase.Log($"Clicked { appName}_menu button");


                    IWebElement link = this.Driver.TryFind(By.Id(appName + buttonSuffix));
                    IntegrationTestBase.Log($"Found { appName}{buttonSuffix} button");

                    link = wait.Until(ExpectedConditions.ElementToBeClickable(link));

                    link.ClickWrapper(this.Driver);
                }, TimeSpan.FromMilliseconds(500), 3).GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"Failed to click on button {buttonSuffix} for app {appName}.", ex);
            }
        }
コード例 #6
0
        /// <summary>
        /// Start a download and wait for a file to appear
        /// https://stackoverflow.com/a/46440261/1141876
        /// </summary>
        /// <param name="expectedName">If we don't know the extension, Chrome creates a temp file in download folder and we think we have the file already</param>
        protected FileInfo ActAndWaitForFileDownload(
            Action action
            , string expectedName
            , TimeSpan maximumWaitTime
            , string downloadDirectory)
        {
            var expectedPath = Path.Combine(downloadDirectory, expectedName);

            try
            {
                File.Delete(expectedPath);
            }
            catch (Exception ex)
            {
                IntegrationTestBase.Log($"Could not delete file {expectedPath }, error: {ex}");
            }
            var stopwatch = Stopwatch.StartNew();

            Assert.IsFalse(File.Exists(expectedPath));
            action();
            IntegrationTestBase.Log($"Action executed");

            var         isTimedOut             = false;
            string      filePath               = null;
            Func <bool> fileAppearedOrTimedOut = () =>
            {
                isTimedOut = stopwatch.Elapsed > maximumWaitTime;
                filePath   = Directory.GetFiles(downloadDirectory)
                             .FirstOrDefault(x => Path.GetFileName(x) == expectedName);
                if (filePath != null)
                {
                    IntegrationTestBase.Log($"File stored at {filePath}");
                }
                else
                {
                    IntegrationTestBase.Log($"File not ready yet. Elapsed: {stopwatch.Elapsed}");
                }

                return(filePath != null || isTimedOut);
            };

            do
            {
                Thread.Sleep(500);
            }while (!fileAppearedOrTimedOut());

            if (!String.IsNullOrEmpty(filePath))
            {
                Assert.AreEqual(expectedPath, filePath);
                return(new FileInfo(filePath));
            }
            if (isTimedOut)
            {
                Assert.Fail("Failed to download");
            }

            return(null);
        }
コード例 #7
0
        public void RecognizeAdminDashboardPage()
        {
            WebDriverWait wait = new WebDriverWait(this.Driver, TimeSpan.FromSeconds(15));

            if (this.Driver.Url.Contains("ChangePassword"))
            {
                IntegrationTestBase.Log("Going from change password page to Admin dashboard");
                this.Driver.Navigate().GoToUrl(this.GetAbsoluteUrl(""));
            }

            wait.Until(x => x.FindElement(By.Id(Strings.Id.PortalSummary)));
        }
コード例 #8
0
        private void InstallMsi3AndVerify(FileInfo msi)
        {
            this.UninstallMsi(Apps.ProductCodes.InstallersTestAppMsi3V1, Apps.Paths.InstallersTestAppMsi3);

            Assert.IsFalse(File.Exists(Apps.Paths.InstallersTestAppMsi3.FullName));
            IntegrationTestBase.Log($"Installing {msi.FullName}.");

            this.InstallMsi(msi, Apps.Paths.InstallersTestAppMsi3);
            IntegrationTestBase.Log($"Finished installing {msi.FullName}.");

            Assert.IsTrue(File.Exists(Apps.Paths.InstallersTestAppMsi3.FullName));
            this.UninstallMsi(Apps.ProductCodes.InstallersTestAppMsi3V1, Apps.Paths.InstallersTestAppMsi3);
            Assert.IsFalse(File.Exists(Apps.Paths.InstallersTestAppMsi3.FullName));
        }
コード例 #9
0
ファイル: DOMExtensions.cs プロジェクト: biplabks/Telimena
        public static IWebElement TryFind(this IWebDriver driver, string id, int timeoutSeconds = 10)
        {
            try
            {
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutSeconds));
                var           ele  = wait.Until(x => x.FindElement(By.Id(id)));
                driver.ExecuteJavaScript("arguments[0].scrollIntoView(true);", ele);
                return(ele);
            }
            catch
            {
                IntegrationTestBase.Log($"***DOM*** Failed to find element by Id {id}");
            }

            return(null);
        }
コード例 #10
0
ファイル: DOMExtensions.cs プロジェクト: biplabks/Telimena
        public static void ClickWrapper(this IWebElement element, IWebDriver driver)
        {
            int    attempt = 0;
            string props   = element?.GetPropertyInfoString();

            while (attempt < 4)
            {
                attempt++;
                try
                {
                    element.Click();
                    IntegrationTestBase.Log($"***DOM*** Click Attempt {attempt} - Successfully clicked on element: {props}");
                    return;
                }
                catch (Exception ex)
                {
                    IntegrationTestBase.Log($"***DOM*** Click Attempt {attempt} - Could not click on element: {props}. {ex}");
                    Actions actions = new Actions(driver);
                    actions.MoveToElement(element).Click().Perform();
                    actions.Perform();
                    driver.ExecuteJavaScript("arguments[0].scrollIntoView(true);", element);
                    Thread.Sleep(500);

                    if (element != null)
                    {
                        try
                        {
                            element.Click();
                        }
                        catch (WebDriverException anotherEx)
                        {
                            if (attempt >= 3)
                            {
                                throw new TelimenaTestException($"Cannot click on [{element?.TagName}] element: [{element?.Text}] regardless of moving it to viewport." +
                                                                anotherEx);
                            }
                            else
                            {
                                IntegrationTestBase.Log($"***DOM*** Click Attempt {attempt} - Could not click on [{element?.TagName}] element: [{element?.Text}] Regardless of moving to viewport. {ex}");
                            }
                        }
                    }
                }
            }
        }
コード例 #11
0
        private string TakeScreenshot(string screenshotName)
        {
            int attempt = 0;

            while (attempt < 5)
            {
                attempt++;
                IntegrationTestBase.Log($"Saving error screenshot: {screenshotName} for test run {TestRunTimestamp}");
                string path = CreatePngPath(screenshotName, this.GetType().Name);
                IntegrationTestBase.Log($"{path}");
                try
                {
                    Screenshot screen = this.Screenshooter.GetScreenshot();
                    screen.SaveAsFile(path, ScreenshotImageFormat.Png);
                    TestContext.AddTestAttachment(path);
                    return(path);
                }
                catch (UnhandledAlertException alertException)
                {
                    IntegrationTestBase.Log($"Attempt {attempt} - Unexpected alert {screenshotName} for test run {TestRunTimestamp}.\r\n{alertException}");

                    IAlert unexpectedAlert = this.Driver.SwitchTo().Alert();
                    IntegrationTestBase.Log($"Attempt {attempt} - Alert text: [{unexpectedAlert?.Text}]");
                    unexpectedAlert?.Dismiss();
                    try
                    {
                        Screenshot screen = this.Screenshooter.GetScreenshot();
                        screen.SaveAsFile(path, ScreenshotImageFormat.Png);
                    }
                    catch (Exception screenshotError)
                    {
                        IntegrationTestBase.Log($"Attempt {attempt} - Error while saving screenshot after dismissing alert: {screenshotError}");
                    }
                }
                catch (Exception screenshotError)
                {
                    IntegrationTestBase.Log($"Attempt {attempt} - Error while saving screenshot: {screenshotError}");
                }
            }

            return("Failed to take screenshot");
        }
コード例 #12
0
ファイル: DOMExtensions.cs プロジェクト: biplabks/Telimena
        public static IWebElement TryFind(this IWebDriver driver, By by, int timeoutSeconds = 10)
        {
            try
            {
                WebDriverWait wait    = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutSeconds));
                var           element = wait.Until(x => x.FindElement(@by));
                Actions       actions = new Actions(driver);
                actions.MoveToElement(element);
                actions.Perform();
                driver.ExecuteJavaScript("arguments[0].scrollIntoView(true);", element);

                return(element);
            }
            catch
            {
                IntegrationTestBase.Log($"***DOM*** Failed to find element using By {@by.ToString()}");
            }

            return(null);
        }
コード例 #13
0
        public void _10_DownloadInstallerTestAppMsi3Package()
        {
            try
            {
                this.UninstallPackages(Apps.ProductCodes.InstallersTestAppMsi3V1
                                       , Apps.ProductCodes.InstallersTestAppMsi3V2);

                IntegrationTestBase.Log("Proceeding to download");

                this.DownloadAndInstallMsiProgramPackage(Apps.Keys.InstallersTestAppMsi3
                                                         , Apps.PackageNames.InstallersTestAppMsi3V1);

                IntegrationTestBase.Log("Uninstalling packages after test");
                this.UninstallPackages(Apps.ProductCodes.InstallersTestAppMsi3V1
                                       , Apps.ProductCodes.InstallersTestAppMsi3V2);
            }
            catch (Exception ex)
            {
                this.HandleError(ex, SharedTestHelpers.GetMethodName());
            }
        }
コード例 #14
0
ファイル: DOMExtensions.cs プロジェクト: biplabks/Telimena
        public static ReadOnlyCollection <IWebElement> TryFindMany(this IWebDriver driver, By by, int timeoutSeconds = 10)
        {
            try
            {
                WebDriverWait wait     = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutSeconds));
                var           elements = wait.Until(x => x.FindElements(@by));
                if (elements.Any())
                {
                    Actions actions = new Actions(driver);
                    actions.MoveToElement(elements.Last());
                    actions.Perform();
                }

                return(elements);
            }
            catch
            {
            }

            IntegrationTestBase.Log("Failed to find elements");
            return(null);
        }
コード例 #15
0
ファイル: DOMExtensions.cs プロジェクト: biplabks/Telimena
        public static IWebElement TryFind(Func <IWebElement> finderFunc, TimeSpan timeout)
        {
            Stopwatch sw = Stopwatch.StartNew();

            while (sw.ElapsedMilliseconds < timeout.TotalMilliseconds)
            {
                try
                {
                    IWebElement result = finderFunc();
                    if (result != null)
                    {
                        return(result);
                    }
                }
                catch
                {
                    //np
                }
            }

            IntegrationTestBase.Log($"***DOM*** Failed to find object within {timeout.TotalMilliseconds}");
            return(null);
        }
コード例 #16
0
        protected IWebElement ExpandAppMenu(string appName)
        {
            var element = this.TryFindAppMenu(appName);

            element.ClickWrapper(this.Driver);
            IntegrationTestBase.Log($"Clicked {appName}_menu button");

            var       parent = element.FindElement(By.XPath("./.."));
            Stopwatch sw     = Stopwatch.StartNew();

            while (!parent.GetAttribute("class").Contains("menu-open"))
            {
                Log($"{appName}_menu not expanded. Reclicking...");
                element = this.TryFindAppMenu(appName);
                element.ClickWrapper(this.Driver);
                IntegrationTestBase.Log($"Clicked {appName}_menu button");
                if (sw.ElapsedMilliseconds > 10000)
                {
                    IntegrationTestBase.Log($"Failed to expand {appName}_menu");
                    Assert.Fail($"Failed to expand {appName}_menu");
                }
            }
            return(element);
        }
コード例 #17
0
 public VersionTuple GetVersionsFromExtractedAppFile(string appName, string testSubfolderName, out FileInfo exe)
 {
     exe = TestAppProvider.ExtractApp(appName, testSubfolderName, x => IntegrationTestBase.Log(x));
     return(this.GetVersionsFromFile(exe));
 }
コード例 #18
0
        public async Task <VersionTuple> GetVersionsFromApp(string appName, string testSubfolderName)
        {
            FileInfo exe = TestAppProvider.ExtractApp(appName, testSubfolderName, x => IntegrationTestBase.Log(x));

            return(await this.GetVersionsFromApp(exe).ConfigureAwait(false));
        }