Automation Tests for your WordPress site – worth of attention?

Writing tests is a common practice in big IT projects. It’s normal if you’re writing a new app, but is this practice worth your attention when you have a WordPress site? Like always, there are “yes” or “no”, it depends… If you have a small site with 5 subpages, it does not make much sense. But if your service, shop has 30+ subpages, it may be a good idea. Imagine that you don’t have to click these 30 pages, but have an app that can make it automatically. For this scenario, you can use the Selenium testing library. This library allows you use several programming languages (like ptyhon, java, c#, javascrtipt etc.). For this example I used c#. Installation is very easy, you need just add Nuget package.

Install-Package Selenium.WebDriver

This is the solution if you use Visual Studio Ide. In case if you use Visual Studio Code write in your terminal:

dotnet add package Selenium.WebDriver

In the first part of the script, Selenium will connect to your page.

[SetUp] public void SetUp()
        {
          driver = new ChromeDriver();

            driver.Navigate().GoToUrl("https://yourwebsite adress");

        }

Now, that’s time to write first test:)

[Test]
        public void MyTest1()
        {
            IWebElement testfield1 = driver.FindElement(By.CssSelector("[id='menu-item-         2433']"));
            testfield1.Click();
         
            string title = driver.Title;
            Assert.False(title.Contains("Page not found"));

        }

This is simple of asseration. In case if title of website will be: “Page not found”, test will be failed. We can check each element of website depending of our test scenario.

Similar Posts