The Add Product to Cart test ensures the add to cart process is working properly for guest customers that visit your store.
During this test Robot Ninja will:
- Visit your product page
- Choose a variation if necessary
- Click the add to cart button
- Confirm the product was successfully added.
To check the product is added to the cart, Robot Ninja will look for WooCommerce's confirmation notice (i.e. the one which says "Product A was added to the cart").
Variable Products and Choosing a Variation
Robot Ninja handles adding variable products and choosing variations in a couple of ways.
If you're testing a variation product, Robot Ninja will already have the product URL with all the chosen attributes set in the URL:
When Robot Ninja loads this page, the variation options will already be filled in/selected so the test will not need to choose any attributes and will move on to press the Add to Cart button.
If you're testing a variable product, Robot Ninja will use the JSON data that WooCommerce loads on every variable product page to find which combination of attributes belongs to a variation that is purchasable.
- Add to Cart button on Product Page - We look for class name:
- Product variations select fields - We use xPath:
- Product variations select options - We look for the html element:
- Product added to cart confirmation notice - We look for the class name:
If Robot Ninja marked this test as skipped make sure you have the Robot Ninja helper plugin activated and have at least one visible product in your store. Robot Ninja should only ever mark this test as skipped if it couldn't find any products to test with your store.
To find out which products were used during testing, view you most recent test, click the "Store Configuration" link within the batch header section and scroll until you find the Robot Ninja Data section. The products used in testing (their IDs and URLs) can be found there.
Here's a list of errors that can cause the Add Product to Cart test to fail and more information about why they failed. If there's a test that is failing and you think it shouldn't be, please email us and we'll have a look for you.
"Robot Ninja could not find the Add to cart button with class name single_add_to_cart_button on product page (PRODUCT URL)."
There's a number of reasons why Robot Ninja could not find the Add to Cart button on your product page:
- If there's a screenshot, first check that the your product page is loading properly. If you're only seeing a blank white screen, try manually visit your PRODUCT URL (as a non-logged in user) to see if the page is loading and there's no PHP fatal errors stopping the page from loading.
- Check that the Add to Cart button is displayed in the screenshot. The first thing Robot Ninja looks for after navigating to your Product Page is the add to cart button. If the product page being visited is a variation product, the default WooCommerce behavior is to disable the add to cart button, but still display it.
- Check that the product is in stock and is purchasable. By default, Robot Ninja should only choose to test products that are in stock and visible to customers, however if you have manually specified a product to test, make sure it's in stock and is purchasable. By default, WooCommerce will not load the Add to Cart button if it's out of stock and/or not purchasable.
"Because the Add to cart button is disabled, Robot Ninja tried to find variations on product page (PRODUCT URL) but failed to find any elements with xPath //*[@class="variations"]/descendant::select"
If you see this error, that means Robot Ninja can see the Add to Cart button but it's not clickable/disabled. The reason this test is failing with this message is because Robot Ninja couldn't find any variation select fields to choose.
Default WooCommerce behavior is to display variation select fields within a
<div class="variations"> and use
<select> elements. If your site is customized to use something other than drop down menus for selecting variations, then that is the reason the test failed.
"Robot Ninja could not find any variation options when looking for elements with a tag on product page (PRODUCT URL)."
Similarly to the reason above. If you see this error, the reason the test failed is because Robot Ninja could not find any <option> elements to select.
Default WooCommerce behavior is to display variation select fields within
<div class="variations"> and use
<select><option> elements to select variations. If your store has customized how variations are displayed then that could be the reason this test is failing. Please get in contact with us (firstname.lastname@example.org) and we'll see if we can update our test code.
"After trying to select variations options, Robot Ninja cannot click the Add to cart button on the product page (PRODUCT URL) because it is still disabled."
At this you should only get this error if the product that is trying to be added to the cart is a variable product. The reason Robot Ninja through this error is because after selecting all available variations, the Add to Cart button was still disabled.
There's a few things you can check:
- If there's a screenshot available for this failure. View the screenshot to see if that highlights any obvious reason why the Add to Cart button is still disabled.
- Using the Product URL provided in the error message, manually visit this URL as a guest customer (non-logged in) and see if you're able to choose the variations and check the add to cart button becomes clickable.
"Unable to find any confirmation that a product was added to the cart (tried looking for any element with class name woocommerce-message)."
Once the Add to Cart button has been clicked, WooCommerce displays a notice to the customer confirming the product has successfully added to the cart.
If your store has removed this notice, that could be the reason Robot Ninja has failed this test.
Customized Add to Cart Process
This test is built with the intention of it working on the majority of WooCommerce stores out there. If you have customized WooCommerce or have purchased a theme that changes WooCommerce in a unique way, then it's possible that this test doesn't work out of the box for you. If this is the case please contact our team in support (email@example.com) and we can discuss updating the existing test or writing a custom test for you at extra cost.