Verifying the notify cog

Verifying the functionality for the notify cog consists of navigating to the products listing page, adding an item to the shopping cart by clicking the Add to Cart button on a listed product, and then verifying that the notification appeared on the web page.

Here is the test suite for the notify cog, which is implemented in the notifycog_test.go source file, located in the client/test/go directory:

package main

import (
"github.com/EngineerKamesh/igb/igweb/client/tests/go/caspertest"
"github.com/gopherjs/gopherjs/js"
)

var wait = js.MakeFunc(func(this *js.Object, arguments []*js.Object) interface{} {
this.Call("waitForSelector", "#primaryContent")
return nil
})

var casper = js.Global.Get("casper")

func main() {

viewportParams := &caspertest.ViewportParams{Object:
js.Global.Get("Object").New()}
viewportParams.Width = 1440
viewportParams.Height = 960
casper.Get("options").Set("viewportSize", viewportParams)

casper.Get("test").Call("begin", "Notify Cog Test Suite", 1,
func(test *js.Object) {
casper.Call("start", "http://localhost:8080/products", wait)
})

// Add an item to the shopping cart
casper.Call("then", func() {
casper.Call("click", ".addToCartButton:nth-child(1)")
})

// Verify that the notification has been displayed
casper.Call("wait", 450, func() {
casper.Get("test").Call("assertSelectorHasText", "#alertify-logs
.alertify-log-success", "Item added to cart", "Display Notify Cog
when item added to shopping cart.")
})

casper.Call("wait", 450, func() {
casper.Call("capture", "screenshots/notify_cog_test.png")
})

// Navigate to Shopping Cart page
casper.Call("then", func() {
casper.Call("click", "a[href^='/shopping-cart']")

})

// Remove product from shopping cart
casper.Call("wait", 450, func() {
casper.Call("click", ".removeFromCartButton:first-child")
})

casper.Call("run", func() {
casper.Get("test").Call("done")
})
}

After setting the web browser's viewport and starting the test suite by navigating to the products listing page, we call the casper object's click method, providing the ".addToCartButton:nth-child(1)" selector. This sends a mouse click event to the first Add to Cart button on the web page.

We wait for 450 milliseconds and then call the tester module's assertSelectorHasText method providing the CSS selector, the text that should exist within the element returned from the selector, and the description of the test as input parameters.

We take a screenshot of the test run (shown in Figure 10.29). We then navigate to the shopping cart page, and remove the item from the shopping cart.

Finally, we call the done method on the tester module object to signify the end of the test suite.

We can run the CasperJS test for the notify cog test suite by issuing the following command:

$ casperjs test js/notifycog_test.js

Figure 10.28 shows a screenshot of the result of running the notify cog test suite:

Figure 10.28: Running the notify cog test suite

Figure 10.29 shows the generated screenshot showing the notification message displayed on the lower right hand corner of the web page as expected:

Figure 10.29: Running the test to verify that the notification message was displayed

We have now verified that the notify cog is functioning as expected and this wraps up our testing of IGWEB's client-side functionality.

Figure 10.30 shows a screenshot of running the whole collection of test suites by running the following command:

$ casperjs test js/*.js
Figure 10.30: Running the whole collection of CasperJS test suites
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.232.189