2017-02-28 20:00:12 +00:00
|
|
|
import config from 'config';
|
|
|
|
import chai from 'chai';
|
|
|
|
import chaiAsPromised from 'chai-as-promised';
|
|
|
|
import test from 'selenium-webdriver/testing';
|
|
|
|
import { WebDriverManager, WebDriverHelper as helper } from 'wp-e2e-webdriver';
|
|
|
|
import { ShopPage, CartPage } from 'wc-e2e-page-objects';
|
|
|
|
|
|
|
|
chai.use( chaiAsPromised );
|
|
|
|
const assert = chai.assert;
|
|
|
|
|
|
|
|
let manager;
|
|
|
|
let driver;
|
|
|
|
|
|
|
|
test.describe( 'Cart page', function() {
|
2017-11-20 12:42:28 +00:00
|
|
|
// open browser
|
|
|
|
test.before( function() {
|
2017-02-28 20:00:12 +00:00
|
|
|
this.timeout( config.get( 'startBrowserTimeoutMs' ) );
|
|
|
|
|
|
|
|
manager = new WebDriverManager( 'chrome', { baseUrl: config.get( 'url' ) } );
|
|
|
|
driver = manager.getDriver();
|
|
|
|
|
|
|
|
helper.clearCookiesAndDeleteLocalStorage( driver );
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.timeout( config.get( 'mochaTimeoutMs' ) );
|
|
|
|
|
|
|
|
test.it( 'should displays no item in the cart', () => {
|
|
|
|
const cartPage = new CartPage( driver, { url: manager.getPageUrl( '/cart' ) } );
|
|
|
|
assert.eventually.equal( cartPage.hasNoItem(), true );
|
|
|
|
} );
|
|
|
|
|
|
|
|
test.it( 'should adds the product to the cart when "Add to cart" is clicked', () => {
|
|
|
|
const shopPage = new ShopPage( driver, { url: manager.getPageUrl( '/shop' ) } );
|
2017-10-31 18:14:19 +00:00
|
|
|
assert.eventually.equal( shopPage.addProductToCart( 'Album' ), true );
|
|
|
|
assert.eventually.equal( shopPage.addProductToCart( 'Polo' ), true );
|
2017-02-28 20:00:12 +00:00
|
|
|
|
|
|
|
const cartPage = new CartPage( driver, { url: manager.getPageUrl( '/cart' ) } );
|
2017-10-31 18:14:19 +00:00
|
|
|
assert.eventually.equal( cartPage.hasItem( 'Album' ), true );
|
|
|
|
assert.eventually.equal( cartPage.hasItem( 'Polo' ), true );
|
2017-02-28 20:00:12 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
test.it( 'should increases item qty when "Add to cart" of the same product is clicked', () => {
|
|
|
|
const shopPage = new ShopPage( driver, { url: manager.getPageUrl( '/shop' ) } );
|
2017-10-31 18:14:19 +00:00
|
|
|
assert.eventually.equal( shopPage.addProductToCart( 'Album' ), true );
|
2017-02-28 20:00:12 +00:00
|
|
|
|
|
|
|
const cartPage = new CartPage( driver, { url: manager.getPageUrl( '/cart' ) } );
|
2017-10-31 18:14:19 +00:00
|
|
|
assert.eventually.equal( cartPage.hasItem( 'Album', { qty: 2 } ), true );
|
|
|
|
assert.eventually.equal( cartPage.hasItem( 'Polo', { qty: 1 } ), true );
|
2017-02-28 20:00:12 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
test.it( 'should updates qty when updated via qty input', () => {
|
|
|
|
const cartPage = new CartPage( driver, { url: manager.getPageUrl( '/cart' ) } );
|
2017-10-31 18:14:19 +00:00
|
|
|
cartPage.getItem( 'Album', { qty: 2 } ).setQty( 4 );
|
2017-02-28 20:00:12 +00:00
|
|
|
cartPage.update();
|
2017-10-31 18:14:19 +00:00
|
|
|
cartPage.getItem( 'Polo', { qty: 1 } ).setQty( 3 );
|
2017-02-28 20:00:12 +00:00
|
|
|
cartPage.update();
|
|
|
|
|
2017-10-31 18:14:19 +00:00
|
|
|
assert.eventually.equal( cartPage.hasItem( 'Album', { qty: 4 } ), true );
|
|
|
|
assert.eventually.equal( cartPage.hasItem( 'Polo', { qty: 3 } ), true );
|
2017-02-28 20:00:12 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
test.it( 'should remove the item from the cart when remove is clicked', () => {
|
|
|
|
const cartPage = new CartPage( driver, { url: manager.getPageUrl( '/cart' ) } );
|
2017-10-31 18:14:19 +00:00
|
|
|
cartPage.getItem( 'Album', { qty: 4 } ).remove();
|
|
|
|
cartPage.getItem( 'Polo', { qty: 3 } ).remove();
|
2017-02-28 20:00:12 +00:00
|
|
|
|
|
|
|
assert.eventually.equal( cartPage.hasNoItem(), true );
|
|
|
|
} );
|
|
|
|
|
|
|
|
test.it( 'should update subtotal in cart totals when adding product to the cart', () => {
|
|
|
|
const shopPage = new ShopPage( driver, { url: manager.getPageUrl( '/shop' ) } );
|
2017-10-31 18:14:19 +00:00
|
|
|
assert.eventually.equal( shopPage.addProductToCart( 'Album' ), true );
|
2017-02-28 20:00:12 +00:00
|
|
|
|
|
|
|
const cartPage = new CartPage( driver, { url: manager.getPageUrl( '/cart' ) } );
|
|
|
|
assert.eventually.equal(
|
2017-10-31 18:14:19 +00:00
|
|
|
cartPage.hasItem( 'Album', { qty: 1 } ),
|
2017-02-28 20:00:12 +00:00
|
|
|
true,
|
2017-10-31 18:14:19 +00:00
|
|
|
'Cart item "Album" with qty 1 is not displayed'
|
2017-02-28 20:00:12 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert.eventually.equal(
|
2017-10-31 18:14:19 +00:00
|
|
|
cartPage.hasSubtotal( '15.00' ),
|
2017-02-28 20:00:12 +00:00
|
|
|
true,
|
2017-10-31 18:14:19 +00:00
|
|
|
'Cart totals does not display subtotal of 15.00'
|
2017-02-28 20:00:12 +00:00
|
|
|
);
|
|
|
|
|
2017-10-31 18:14:19 +00:00
|
|
|
cartPage.getItem( 'Album', { qty: 1 } ).setQty( 2 );
|
2017-02-28 20:00:12 +00:00
|
|
|
cartPage.update();
|
|
|
|
|
|
|
|
assert.eventually.equal(
|
2017-10-31 18:14:19 +00:00
|
|
|
cartPage.hasSubtotal( '30.00' ),
|
2017-02-28 20:00:12 +00:00
|
|
|
true,
|
2017-10-31 18:14:19 +00:00
|
|
|
'Cart totals does not display subtotal of 30.00'
|
2017-02-28 20:00:12 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2017-11-20 12:36:49 +00:00
|
|
|
test.it( 'should go to the checkout page when "Proceed to Checkout" is clicked', () => {
|
2017-02-28 20:00:12 +00:00
|
|
|
const cartPage = new CartPage( driver, { url: manager.getPageUrl( '/cart' ) } );
|
|
|
|
const checkoutPage = cartPage.checkout();
|
|
|
|
|
|
|
|
assert.eventually.equal(
|
|
|
|
checkoutPage.components.orderReview.displayed(),
|
|
|
|
true,
|
|
|
|
'Order review in checkout page is not displayed'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2018-06-07 14:31:37 +00:00
|
|
|
// take screenshot
|
|
|
|
test.afterEach( function() {
|
|
|
|
if ( this.currentTest.state === 'failed' ) {
|
|
|
|
helper.takeScreenshot( manager, this.currentTest );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2017-11-20 12:42:28 +00:00
|
|
|
// quit browser
|
|
|
|
test.after( () => {
|
2017-02-28 20:00:12 +00:00
|
|
|
manager.quitBrowser();
|
|
|
|
} );
|
|
|
|
} );
|