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 { WPLogin } from 'wp-e2e-page-objects';
|
|
|
|
import { WPAdminProductNew } from 'wc-e2e-page-objects';
|
|
|
|
|
|
|
|
chai.use( chaiAsPromised );
|
|
|
|
const assert = chai.assert;
|
|
|
|
|
|
|
|
let manager;
|
|
|
|
let driver;
|
|
|
|
|
|
|
|
test.describe( 'Add New Product 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' ) );
|
|
|
|
|
2017-11-20 12:42:28 +00:00
|
|
|
// login
|
|
|
|
test.before( () => {
|
2017-02-28 20:00:12 +00:00
|
|
|
const wpLogin = new WPLogin( driver, { url: manager.getPageUrl( '/wp-login.php' ) } );
|
|
|
|
wpLogin.login( config.get( 'users.admin.username' ), config.get( 'users.admin.password' ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
test.it( 'can create simple virtual product titled "Simple Product" with regular price $9.99', () => {
|
|
|
|
const product = new WPAdminProductNew( driver, { url: manager.getPageUrl( '/wp-admin/post-new.php?post_type=product' ) } );
|
|
|
|
product.setTitle( 'Simple Product' );
|
|
|
|
|
|
|
|
const productData = product.components.metaBoxProductData;
|
|
|
|
productData.selectProductType( 'Simple product' );
|
|
|
|
productData.checkVirtual();
|
|
|
|
|
|
|
|
const panelGeneral = productData.clickTab( 'General' );
|
|
|
|
panelGeneral.setRegularPrice( '9.99' );
|
|
|
|
|
|
|
|
product.publish();
|
|
|
|
assert.eventually.ok( product.hasNotice( 'Product published.' ) );
|
|
|
|
|
|
|
|
product.moveToTrash();
|
|
|
|
assert.eventually.ok( product.hasNotice( '1 product moved to the Trash.' ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
test.it( 'can create product with variations', () => {
|
|
|
|
const product = new WPAdminProductNew( driver, { url: manager.getPageUrl( '/wp-admin/post-new.php?post_type=product' ) } );
|
|
|
|
product.setTitle( 'Variable Product with Two Variations' );
|
|
|
|
|
|
|
|
const productData = product.components.metaBoxProductData;
|
|
|
|
productData.selectProductType( 'Variable product' );
|
|
|
|
|
|
|
|
const panelAttributes = productData.clickTab( 'Attributes' );
|
|
|
|
panelAttributes.selectAttribute( 'Custom product attribute' );
|
|
|
|
|
|
|
|
const attr1 = panelAttributes.add();
|
|
|
|
assert.eventually.ok( attr1.displayed() );
|
|
|
|
attr1.setName( 'attr #1' );
|
|
|
|
attr1.checkVisibleOnTheProductPage();
|
|
|
|
attr1.checkUsedForVariations();
|
|
|
|
attr1.setValue( 'val1 | val2' );
|
|
|
|
attr1.toggle();
|
|
|
|
|
|
|
|
const attr2 = panelAttributes.add();
|
2018-04-25 08:00:10 +00:00
|
|
|
assert.eventually.ok( attr2.displayed() );
|
2017-02-28 20:00:12 +00:00
|
|
|
attr2.setName( 'attr #2' );
|
|
|
|
attr2.checkVisibleOnTheProductPage();
|
|
|
|
attr2.checkUsedForVariations();
|
|
|
|
attr2.setValue( 'val1 | val2' );
|
|
|
|
|
|
|
|
const attr3 = panelAttributes.add();
|
2018-04-25 08:00:10 +00:00
|
|
|
assert.eventually.ok( attr3.displayed() );
|
2017-02-28 20:00:12 +00:00
|
|
|
attr3.setName( 'attr #3' );
|
|
|
|
attr3.checkVisibleOnTheProductPage();
|
|
|
|
attr3.checkUsedForVariations();
|
|
|
|
attr3.setValue( 'val1 | val2' );
|
|
|
|
attr3.toggle(); attr2.toggle();
|
|
|
|
|
|
|
|
panelAttributes.saveAttributes();
|
|
|
|
|
|
|
|
const panelVaritions = productData.clickTab( 'Variations' );
|
|
|
|
panelVaritions.selectAction( 'Create variations from all attributes' );
|
|
|
|
panelVaritions.go();
|
|
|
|
|
|
|
|
const var1 = panelVaritions.getRow( 1 );
|
|
|
|
var1.toggle();
|
|
|
|
var1.checkEnabled();
|
|
|
|
var1.checkVirtual();
|
|
|
|
var1.setRegularPrice( '9.99' );
|
|
|
|
|
|
|
|
const var2 = panelVaritions.getRow( 2 );
|
|
|
|
var2.toggle();
|
|
|
|
var2.checkEnabled();
|
|
|
|
var2.checkVirtual();
|
|
|
|
var2.setRegularPrice( '11.99' );
|
|
|
|
|
|
|
|
const var3 = panelVaritions.getRow( 3 );
|
|
|
|
var3.toggle();
|
|
|
|
var3.checkEnabled();
|
|
|
|
var3.checkManageStock();
|
|
|
|
var3.setRegularPrice( '20' );
|
|
|
|
var3.setWeight( '200' );
|
|
|
|
var3.setDimensionLength( '10' );
|
|
|
|
var3.setDimensionWidth( '20' );
|
|
|
|
var3.setDimensionHeight( '15' );
|
|
|
|
|
|
|
|
panelVaritions.saveChanges();
|
|
|
|
|
|
|
|
helper.scrollUp( driver );
|
|
|
|
helper.scrollUp( driver );
|
|
|
|
helper.scrollUp( driver );
|
|
|
|
|
|
|
|
product.publish();
|
|
|
|
assert.eventually.ok( product.hasNotice( 'Product published.' ) );
|
|
|
|
|
|
|
|
product.moveToTrash();
|
|
|
|
assert.eventually.ok( product.hasNotice( '1 product moved to the Trash.' ) );
|
|
|
|
} );
|
|
|
|
|
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();
|
|
|
|
} );
|
|
|
|
} );
|