0

Trying to use the webdriver to do some automated testing with crm. Im having issues with consistency. Ill run a test and it'll pass and the next time it will fail.I tried using waits and am still having this isuse. Has anyone used crm and selenium together and know any ideas on how to fix this issue?

IWebDriver driver = new FirefoxDriver();

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
            // Thread.Sleep(10000);
            driver.Navigate().GoToUrl("https://login.microsoftonline.com/ea791863-b17d-43ec-90ba-148d3fa0a86f/wsfed?wa=wsignin1.0&wtrealm=https%3a%2f%2fmerlintest.crm.dynamics.com%2f&wctx=pr%3dwsfederation%26rm%3dhttps%253a%252f%252fmerlintest.crm.dynamics.com%252f%26ry%3dhttps%253a%252f%252fmerlintest.crm.dynamics.com%252fmain.aspx&wct=2017-07-05T20%3a42%3a50Z&wreply=https%3a%2f%2fcloudredirector.crm.dynamics.com%3a443%2fG%2fAuthRedirect%2fIndex.aspx%3fRedirectTo%3dhttps%253a%252f%252fmerlintest.crm.dynamics.com%252fmain.aspx#386670653");
            IWebElement emailOrPhone = driver.FindElement(By.Id("cred_userid_inputtext")); //email or phone input
            IWebElement password = driver.FindElement(By.Id("cred_password_inputtext"));//password input
            emailOrPhone.SendKeys("email");
            password.SendKeys("password");

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("cred_sign_in_button")));
            IWebElement enterButton = driver.FindElement(By.Id("cred_sign_in_button"));

            enterButton.SendKeys(Keys.Enter);//login
            driver.SwitchTo().DefaultContent();//switches frames ,needed this so we can grab elements



            Thread.Sleep(5000);
          //navigate to search box and enter candidate name
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementExists((By.ClassName("navImageFlipHorizontal"))));
            driver.FindElement(By.ClassName("navImageFlipHorizontal")).Click();

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            Thread.Sleep(5000);

            driver.FindElement(By.Id("navTabButtonSearchD365Id")).SendKeys("");
            driver.FindElement(By.Id("findCriteriaImg")).Click();

            WebDriverWait iwait = new WebDriverWait(driver, TimeSpan.FromSeconds(25));
            IWebElement element = iwait.Until(
                    ExpectedConditions.ElementIsVisible(By.Id("searchTextBox")));
            Thread.Sleep(5000);
            driver.FindElement(By.Id("searchTextBox")).Clear();
            driver.FindElement(By.Id("searchTextBox")).SendKeys("lisa steinburg");
            driver.FindElement(By.Id("searchTextBox")).SendKeys(Keys.Enter);
8
  • How is it failing? Is it not finding an element that it found on the previous run?
    – Gilles
    Jul 11, 2017 at 13:51
  • sorry, yes it will say that but then the next time it will find it and its not always the same one.
    – amberl
    Jul 11, 2017 at 14:13
  • I'd suggest not setting implicit waits anywhere in your code (driver.Manage().Timeouts().ImplicitWait), or at least take it out when first writing and debugging your tests. In my experience this causes a ton of confusion with flaky tests just like what you're seeing. Without that, you'll see more clearly exactly where your tests need to do explicit waits for some condition on the page to be met before elements will be stable enough to interact with.
    – mrfreester
    Jul 11, 2017 at 19:30
  • An additional side note about ImplicitWait, you're setting it to be 10 seconds, and then a few lines later, you're setting it to 10 seconds again. Once you set ImplicitWait, it'll be that from then on, even for subsequent tests, so there is no need to set it to the same value twice. It basically means, wait up to that amount of time when finding elements for them to exist, which is not the same thing as waiting for them to be stable.
    – mrfreester
    Jul 11, 2017 at 19:34
  • As for your current issue/issues. Are there certain elements it usually is failing on? You probably need to take out your sleeps as well. If a sleep makes a test pass, it's a good sign that there is something happening on the page that you can explicitly wait for to make your test more stable, and faster
    – mrfreester
    Jul 11, 2017 at 19:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy