-
Notifications
You must be signed in to change notification settings - Fork 0
/
productOrder.js
85 lines (68 loc) · 2.71 KB
/
productOrder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const {Builder, By, until} = require('selenium-webdriver');
const test = require('selenium-webdriver/testing');
const expect = require('chai').expect;
test.describe('Product order', function() {
let driver;
const homePage = 'http://172.14.14.128/litecart/'; //!!!CHANGE TO LOCALHOST
test.before(function *() {
driver = yield new Builder()
.forBrowser('chrome')
.build();
driver.manage().timeouts().implicitlyWait(3000)
});
test.it('Check products ordering', function*() {
const products = ['[alt="Green Duck"]', '[alt="Purple Duck"]', '[alt="Red Duck"]'];
function _getByName(name) {
return driver.findElement(By.name(name))
}
function _getByCss(css) {
return driver.findElement(By.css(css))
}
function _getByXpath(xpath) {
return driver.findElement(By.xpath(xpath))
}
// const productPage = homePage + 'en/rubber-ducks-c-1/subcategory-c-2/green-duck-p-2';
function openHomepage() {
return driver.get(homePage);
}
function openProduct(i) {
return _getByCss(products[i]).click();
}
function addProductToCart() {
return _getByName('add_cart_product').click();
}
function isProductNumbersInCart(numbers) {
numbers++;
return _getByXpath('//*[@id="cart"]//*[@class="quantity"][.="'+ numbers +'"]')
.then(_=> {return true})
.catch(_=> {return false})
}
function checkOut() {
return _getByCss('#cart a:last-child').click();
}
function removeProductFromCart(products) {
_getByName('remove_cart_item').click();
}
function getLastProductInCart(i) {
return _getByXpath('(//td[@class="item"])['+ i +']');
}
function checkProductRemoved(element) {
return driver.wait(until.stalenessOf(element), 4000)
.then(_=>{return true})
.catch(_=>{return false})
}
for (let i=0; i<products.length; i++){
openHomepage();
openProduct(i);
addProductToCart();
expect(yield isProductNumbersInCart(i)).to.equal(true, ' Количество товаров не соответствует');
}
checkOut();
for (let i=products.length; i; i--){
let lastProduct = yield getLastProductInCart(i);
removeProductFromCart();
expect(yield checkProductRemoved(lastProduct)).to.equal(true, 'Товар не удален из списка');
}
});
test.after(() => driver.quit());
});