WooCommerce Testing
WooCommerce transforms ordinary WordPress websites into complete online shops with its open-source and adaptable features. It has many different functions, such as safe payment methods, adjustable delivery choices, and so on, which you can customize for your own business requirements.
The plugin comes with many add-ons that provide extra features like making reservations, handling recurring payments, and working together with different software applications. WooCommerce is mainly created with PHP, the same programming language that WordPress uses.
PHP is a server-side scripting language widely used for web development. Besides PHP, WooCommerce utilizes different web technologies for both its user interface and server-side operations.
According to the testing pyramid, you can test your WooCommerce application through
Unit Testing
As a project grows, it becomes difficult to keep track of every single method and class written. Through unit testing, you can ensure that your methods and classes, that is, various units of code, are working as expected.
Like WordPress, WooCommerce works with PHP. Thus, PHPUnit is the best way to get your unit testing done. When it comes to unit testing, you want your test cases to be lightweight and focus on just a single outcome at a test case level. You can make use of stubs and mocking to mimic all those complex WordPress functionalities without booting the entire application for every test run.
There are some pre-defined unit tests that you can import and use to test your project, along with creating custom test cases. Using these pre-defined test cases also gives you access to a couple of useful helper functions, like creating customers or sample orders.
// Use the necessary PHPUnit and WooCommerce classes class ProductFunctionsTest extends TestCase { private $product_id_on_sale; private $product_id_not_on_sale; protected function setUp(): void { $this->product_id_on_sale = $this->create_product(true); //on sale product $this->product_id_not_on_sale = $this->create_product(false); //not on sale product } private function create_product($on_sale) { $product = new WC_Product_Simple(); $product->set_regular_price(10); if ($on_sale) { $product->set_sale_price(5); } $product->save(); return $product->get_id(); } // Test if 'is_product_on_sale' returns true for products on sale public function testProductOnSale() { $this->assertTrue(is_product_on_sale($this->product_id_on_sale), 'Product should be on sale'); } // Test if 'is_product_on_sale' returns false for products not on sale public function testProductNotOnSale() { $this->assertFalse(is_product_on_sale($this->product_id_not_on_sale), 'Product should not be on sale'); } // Clean up the created products protected function tearDown(): void { wp_delete_post($this->product_id_on_sale); wp_delete_post($this->product_id_not_on_sale); } }
Integration Testing
Through integration testing, you can ascertain if different modules are working properly together or not. In websites dealing with online stores, you will have the need for this. As the project grows, you need to have such checks and balances where the interworking of modules is tested instead of relying completely on end-to-end testing for it.
Here are some scenarios where you might need to perform integration testing:
- Plugins/Extensions: You need to test how your own-made plugins or extensions from others work with WooCommerce’s main functions.
- External Services: When we do integration testing, it also includes checking how well the system works with outside services like those that calculate shipping costs, figure out taxes, manage customer relationships, and analyze data.
- Subscriptions: When your application integrates WooCommerce subscriptions, it’s important to check the ongoing payment system, the renewal of subscriptions, and how users control their subscriptions.
- Order Management UI: Checking the connection between our system for handling orders and what customers see on their screens covers placing orders, tracking order progress, managing stock levels, and linking up with delivery services.
- Account Management Services: Making certain that the functionalities for user sign up, signing in, password changing, and managing account details integrate smoothly with the WooCommerce shop.
You can use the same tools you used for unit testing, like PHPUnit, to write integration tests.
End-to-End Testing
Imagine if your customer placed an order but is not able to see a confirmation for the same. This will impact business and create a bad reputation for the company. When it comes to websites behaving as storefronts, ensuring that common workflows are functioning properly is a must-have.
This is where end-to-end testing comes in, as it looks at verifying user workflows. End-to-end testing is focused on the user’s experience of the product rather than the developer’s.
There are many tools in the market that can be used to perform end-to-end testing on WooCommerce-based applications.
Selenium
Selenium is a well-known open-source framework that enables you to automate many different testing scenarios from start to finish. WebDriver plays a vital role in Selenium, enabling users to program browser tasks like opening websites, clicking on links, completing forms, and retrieving information from web pages.
Selenium also gives ways to confirm and check different elements and attributes on websites, helping users make sure the expected actions and information are correct. It supports various programming languages like Java, Python, C#, Ruby, and more.
However, Selenium has limitations, such as the need for a lot of work to maintain tests, challenges with testing across different platforms, and some instability from using locators based on elements like CSS and XPaths.
testRigor
Software testing has come a long way since the incorporation of AI. This has made it simpler to create tests and lessened the time needed for maintaining them, expanding its influence broadly.
Evidence can be seen in the growing amount of tools for test automation that provide these advantages. One such generative AI-powered tool is testRigor.
testRigor overcomes Selenium’s limitations by leveraging AI to give you a seamless testing experience. It emulates a human tester to give you an unparalleled experience.
Using this tool you can create test cases in plain English language without worrying about XPaths or CSS locators of UI elements. Even test maintenance efforts are reduced drastically through self-healing.
login navigate to catalog check that page contains "Chargable toothbrush C511X" to the left of "$50" click on "Order" below "Chargable toothbrush C511X" check that page contains "Chargable toothbrush C422W" to the left of "$60" click "Order" below "Chargable toothbrush C422W" click "cart" click "checkout" check that page contains "2 items" check that page contains "Order total : $110"
Not just that, it also offers great features that make testing easy across different platforms. This proves useful since WooCommerce can also be integrated into mobile apps for cross-platform testing. If you wish to integrate your tests with CI/CD pipelines, you can easily do so by utilizing the various integrations testRigor offers.
How to do End-to-end Testing with testRigor
Let us take the example of an e-commerce website that sells plants and other gardening needs. We will create end-to-end test cases in testRigor using plain English test steps.
Step 1: Log in to your testRigor app with your credentials.
Step 2: Set up the test suite for the website testing by providing the information below:
- Test Suite Name: Provide a relevant and self-explanatory name.
- Type of testing: Select from the following options: Desktop Web Testing, Mobile Web Testing, Native and Hybrid Mobile, based on your test requirements.
- URL to run test on: Provide the application URL that you want to test.
- Testing credentials for your web/mobile app to test functionality which requires user to login: You can provide the app’s user login credentials here and need not write them separately in the test steps then. The login functionality will be taken care of automatically using the keyword
login
. - OS and Browser: Choose the OS Browser combination on which you want to run the test cases.
- Number of test cases to generate using AI: If you wish, you can choose to generate test cases based on the App Description text, which works on generative AI.
Step 3: Click Create Test Suite.
On the next screen, you can let AI generate the test case based on the App Description you provided during the Test Suite creation. However, for now, select do not generate any test, since we will write the test steps ourselves.
Step 4: To create a new custom test case yourself, click Add Custom Test Case.
Step 5: Provide the test case Description and start adding the test steps.
For the application under test, i.e., e-commerce website, we will perform below test steps:
- Search for a product
- Add it to the cart
- Verify that the product is present in the cart
Test Case: Search and Add to Cart
Step 1: We will add test steps on the test case editor screen one by one.
testRigor automatically navigates to the website URL you provided during the Test Suite creation. There is no need to use any separate function for it. Here is the website homepage, which we intend to test.
First, we want to search for a product in the search box. Unlike traditional testing tools, you can identify the UI element using the text you see on the screen. You need not use any CSS/XPath identifiers.
click "What are you looking for?"
Step 2: Once the cursor is in the search box, we will type the product name (lily), and press enter to start the search.
type "lily" enter enter
Search lists all products with the “lily” keyword on the webpage.
Step 3: The lily plant we are searching for needs the screen to be scrolled; for that testRigor provides a command. Scroll down until the product is present on the screen:
scroll down until page contains "Zephyranthes Lily, Rain Lily (Red)"
When the product is found on the screen, testRigor stops scrolling.
Step 4: Click on the product name to view the details:
click "Zephyranthes Lily, Rain Lily (Red)"
After the click, the product details are displayed on the screen as below, with the default Quantity as 1.
Step 5: Lets say, we want to change the Quantity to 3, so here we use the testRigor command to select from a list.
select "3" from "Quantity"
click "Add to cart"
The product is successfully added to the cart, and the “Added to your cart:” message is displayed on webpage.
Step 6: To assert that the message is successfully displayed, use a simple assertion command as below:
check that page contains "Added to your cart:"
Step 7: After this check, we will view the contents of the cart by clicking View cart as below:
click "View cart"
Step 8: Now we will again check that the product is present in the cart, under heading “Your cart” using the below assertion. With testRigor, it is really easy to specify the location of an element on the screen.
check that page contains "Zephyranthes Lily, Rain Lily (Red)" under "Your cart"
Complete Test Case
Here is how the complete test case will look in the testRigor app. The test steps are simple in plain English, enabling everyone in your team to write and execute them.
Click Add and Run.
Execution Results
Once the test is executed, you can view the execution details, such as execution status, time spent in execution, screenshots, error messages, logs, video recordings of the test execution, etc. In case of any failure, there are logs and error text that are available easily in a few clicks.
You can also download the complete execution with steps and screenshots in PDF or Word format through the View Execution option.
testRigor’s Capabilities
Apart from the simplistic test case design and execution, there are some advanced features that help you test your application using simple English commands.
- Reusable Rules (Subroutines): You can easily create functions for the test steps that you use repeatedly. You can use the Reusable Rules to create such functions and call them in test cases by simply writing their names. See the example of Reusable Rules.
- Global Variables and Data Sets: You can import data from external files or create your own global variables and data sets in testRigor to use them in data-driven testing.
- 2FA, QR Code, and Captcha Resolution: testRigor easily manages the 2FA, QR Code, and Captcha resolution through its simple English commands.
- Email, Phone Call, and SMS Testing: Use simple English commands to test the email, phone calls, and SMS. These commands are useful for validating 2FA scenarios, with OTPs and authentication codes being sent to email, phone calls, or via phone text.
- File Upload/ Download Testing: Execute the test steps involving file download or file upload without the requirement of any third-party software. You can also validate the contents of the files using testRigor’s simple English commands.
- Database Testing: Execute database queries and validate the results fetched.
testRigor enables you to test web, mobile (hybrid, native), API, and desktop apps with minimum effort and maintenance.
Additional Resources
- Access testRigor documentation to know about more useful capabilities
- Top testRigor’s features
- How to perform end-to-end testing
Conclusion
Using WooCommerce, you can make your website function as an online store with ease. As it is an open-source plugin, you can modify the existing functions to match what you need.
But for businesses using WooCommerce, you need a test automation tool that makes very little trouble and provides precise testing outcomes quickly. Before you decide on testing tools, make sure to do careful research and choose one that meets your requirements.
Achieve More Than 90% Test Automation | |
Step by Step Walkthroughs and Help | |
14 Day Free Trial, Cancel Anytime |