7

How can I use Selenium for SharePoint functionality testing? Can anyone provide me a link or a book which I can use for learning SharePoint automation testing using selenium?

  • 19 views and 3 upvotes and still no answers! :'( – Anand Dec 5 '16 at 12:10
7

Selenium is automation testing tool and has nothing to do with SharePoint. We can use it test any of the web application including SharePoint. Selenium offer two ways of testing a web application:

  1. Selenium IDE: This is a browser based plugin and used to record testing steps and play them back. It generates a HTML based file to keep all the steps recorded. It has its own simple language and can be used for quick testing.
  2. Selenium WebDriver: This is most robust way of doing automation testing with Selenium. It provides you an ease of picking the language you prefer and write your automation test case. One of the advantage of this is easy script sharing and you can create your own testing framework for quick/efficient testing.

I was doing some RnD of this Selenium and created a script to login into SPO. You take help of this script and get started on it. This is a C# console application based project.

class Program
    {
        static void Main(string[] args)
        {
            //IWebDriver driver = new InternetExplorerDriver();
            FirefoxProfile profile = new FirefoxProfile();
            profile.SetPreference("browser.privatebrowsing.autostart", true);
            IWebDriver driver = new FirefoxDriver(profile);

            SharePointTesting testCase = new SharePointTesting(driver);
            testCase.Login("https://domain.sharepoint.com");
            testCase.OpenListNewItem("https://domain.sharepoint.com/Shared Documents/");
        }


    }

And following is SharePointTesting class implementation.

class SharePointTesting
    {
        IWebDriver driver;

        public SharePointTesting(IWebDriver browser)
        {
            driver = browser;
        }

        public void Login(string url)
        {
            driver.Url = url;

            var email = driver.FindElement(By.Name("login"));
            email.SendKeys("userName");
            email.SendKeys(Keys.Tab);

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            var password = wait.Until(d =>
            {
                var redirect = d.FindElement(By.Id("redirect_dots_animation"));
                var style = redirect.GetAttribute("style");
                if (style != "visibility: hidden;")
                {
                    return null;
                }
                else
                {
                    return driver.FindElement(By.Name("passwd"));
                }
            });

            password.SendKeys("password");

            var btnSignIn = driver.FindElement(By.Id("cred_sign_in_button"));
            btnSignIn.Click();
            //btnSignIn.Submit();
        }

        public void OpenListNewItem(string listUrl)
        {
            driver.Url = listUrl;
        }
    }

This code, actually opens firefox browser in private browsing, put the email/username in designated field and then wait until SPO check for login redirection or wait till 10sec and then put password into password box. After this, it clicks on sign in button. When this process is complete, it redirect to a document library page.

  • Do I have to use any plugins to download any plugin or template to run the above code? – Anand Aug 1 '17 at 18:22
  • Yes, Selenium IDE is a browser based plugin which you can download from browser pulgin/add-ons sections. While Selenium WebDriver are libraries available for multiple language. The above example uses C#, so you can find the Selenium Nuget package and add them to your project. – ThinkB4Code Aug 2 '17 at 5:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.