2017-10-06 20:10:50 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
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 { SingleProductPage, CartPage } from 'wc-e2e-page-objects';
|
|
|
|
|
|
|
|
chai.use( chaiAsPromised );
|
|
|
|
|
|
|
|
const assert = chai.assert;
|
|
|
|
|
|
|
|
let manager;
|
|
|
|
let driver;
|
|
|
|
|
|
|
|
test.describe( 'Single Product Page', function() {
|
2017-12-13 20:14:53 +00:00
|
|
|
const visitProductByPath = path => {
|
|
|
|
return new SingleProductPage( driver, { url: manager.getPageUrl( path ) } );
|
|
|
|
};
|
|
|
|
const visitCart = () => {
|
|
|
|
return new CartPage( driver, { url: manager.getPageUrl( '/cart' ) } );
|
|
|
|
};
|
|
|
|
|
2017-11-20 12:42:28 +00:00
|
|
|
// open browser
|
|
|
|
test.before( function() {
|
2017-10-06 20:10:50 +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 be able to add simple products to the cart', () => {
|
2017-12-13 20:14:53 +00:00
|
|
|
const productPage = visitProductByPath( '/product/t-shirt' );
|
2017-10-06 20:10:50 +00:00
|
|
|
productPage.setQuantity( 5 );
|
|
|
|
productPage.addToCart();
|
|
|
|
|
2017-12-13 20:14:53 +00:00
|
|
|
assert.eventually.equal( visitCart().hasItem( 'T-Shirt', { qty: 5 } ), true );
|
2017-10-06 20:10:50 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
test.it( 'should be able to add variation products to the cart', () => {
|
2017-12-13 20:14:53 +00:00
|
|
|
let variableProductPage;
|
2017-10-06 20:10:50 +00:00
|
|
|
|
2017-12-13 20:14:53 +00:00
|
|
|
variableProductPage = visitProductByPath( '/product/hoodie' );
|
|
|
|
variableProductPage.selectVariation( 'Color', 'Blue' );
|
|
|
|
variableProductPage.selectVariation( 'Logo', 'Yes' );
|
2017-10-06 20:10:50 +00:00
|
|
|
driver.sleep( 500 );
|
2017-12-13 20:14:53 +00:00
|
|
|
variableProductPage.addToCart();
|
|
|
|
assert.eventually.ok( visitCart().hasItem( 'Hoodie - Blue, Yes' ), '"Hoodie - Blue, Yes" in the cart' );
|
2017-10-06 20:10:50 +00:00
|
|
|
|
2017-12-13 20:14:53 +00:00
|
|
|
variableProductPage = visitProductByPath( '/product/hoodie' );
|
2017-10-06 20:10:50 +00:00
|
|
|
variableProductPage.selectVariation( 'Color', 'Green' );
|
2017-12-13 20:14:53 +00:00
|
|
|
variableProductPage.selectVariation( 'Logo', 'No' );
|
|
|
|
driver.sleep( 500 );
|
2017-10-06 20:10:50 +00:00
|
|
|
variableProductPage.addToCart();
|
2017-12-13 20:14:53 +00:00
|
|
|
assert.eventually.ok( visitCart().hasItem( 'Hoodie - Green, No' ), '"Hoodie - Green, No" in the cart' );
|
2017-10-06 20:10:50 +00:00
|
|
|
} );
|
|
|
|
|
2017-11-20 12:42:28 +00:00
|
|
|
// quit browser
|
|
|
|
test.after( () => {
|
2017-10-06 20:10:50 +00:00
|
|
|
manager.quitBrowser();
|
|
|
|
} );
|
|
|
|
} );
|