-
Notifications
You must be signed in to change notification settings - Fork 1
/
shopify.js
171 lines (147 loc) · 5.36 KB
/
shopify.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const puppeteer = require('puppeteer');
const runTime = (startTime, endTime) => (endTime - startTime) / 1000;
const shopifyTest = async () => {
let startTime, endTime;
try {
const browser = await puppeteer.launch({
headless: false,
slowMo: 20,
args: ['--window-position=1280,0', '--window-size=1280,1220'],
});
const page = await browser.newPage();
await page.setCacheEnabled(false);
const navigationPromise = page.waitForNavigation({
waitUntil: ['load', 'domcontentloaded'],
});
startTime = new Date();
// 1. Open a store
await page.goto('https://storefrontify.com/');
await page.setViewport({ width: 1280, height: 1220 });
await navigationPromise;
// 2. Click on Garden collection
await page.waitForSelector(
'#AccessibleNav > #SiteNav > li:nth-child(2) > .site-nav__link > .site-nav__label'
);
await page.click(
'#AccessibleNav > #SiteNav > li:nth-child(2) > .site-nav__link > .site-nav__label'
);
await navigationPromise;
// 3. Go to second page of collection
await page.waitForSelector(
'#Collection > .list--inline > li > .btn > .icon-arrow-right'
);
await page.click(
'#Collection > .list--inline > li > .btn > .icon-arrow-right'
);
await navigationPromise;
// 4. Cleck on "Cream Sofa" product
await page.waitForSelector(
'#Collection > .grid > .grid__item:nth-child(5) > .grid-view-item > .grid-view-item__link'
);
await page.click(
'#Collection > .grid > .grid__item:nth-child(5) > .grid-view-item > .grid-view-item__link'
);
await navigationPromise;
// 5. Add to cart
await page.waitForSelector(
'.grid__item > .product-single__meta > #product_form_4184602214484 > .product-form__item > .btn'
);
await page.click(
'.grid__item > .product-single__meta > #product_form_4184602214484 > .product-form__item > .btn'
);
await navigationPromise;
//6. Back to main page
await page.waitForSelector(
'.site-header > .grid > .grid__item > .h2 > .site-header__logo-link'
);
await page.click(
'.site-header > .grid > .grid__item > .h2 > .site-header__logo-link'
);
await navigationPromise;
// 7. Visit Apparel collection
await page.waitForSelector(
'#AccessibleNav > #SiteNav > li:nth-child(3) > .site-nav__link > .site-nav__label'
);
await page.click(
'#AccessibleNav > #SiteNav > li:nth-child(3) > .site-nav__link > .site-nav__label'
);
await navigationPromise;
// 8. 1st product in collection
await page.waitForSelector(
'#Collection > .grid > .grid__item:nth-child(1) > .grid-view-item > .grid-view-item__link'
);
await page.click(
'#Collection > .grid > .grid__item:nth-child(1) > .grid-view-item > .grid-view-item__link'
);
await navigationPromise;
// 9. back to collection
await page.waitForSelector(
'#AccessibleNav > #SiteNav > .site-nav--active > .site-nav__link > .site-nav__label'
);
await page.click(
'#AccessibleNav > #SiteNav > .site-nav--active > .site-nav__link > .site-nav__label'
);
await navigationPromise;
// 10. 2nd product in collection
await page.waitForSelector(
'#Collection > .grid > .grid__item:nth-child(2) > .grid-view-item > .grid-view-item__link'
);
await page.click(
'#Collection > .grid > .grid__item:nth-child(2) > .grid-view-item > .grid-view-item__link'
);
await navigationPromise;
// 11. back to collection
await page.waitForSelector(
'#AccessibleNav > #SiteNav > .site-nav--active > .site-nav__link > .site-nav__label'
);
await page.click(
'#AccessibleNav > #SiteNav > .site-nav--active > .site-nav__link > .site-nav__label'
);
await navigationPromise;
// 12. 3rd product
await page.waitForSelector(
'#Collection > .grid > .grid__item:nth-child(3) > .grid-view-item > .grid-view-item__link'
);
await page.click(
'#Collection > .grid > .grid__item:nth-child(3) > .grid-view-item > .grid-view-item__link'
);
await navigationPromise;
// 13. back
await page.waitForSelector(
'#AccessibleNav > #SiteNav > .site-nav--active > .site-nav__link > .site-nav__label'
);
await page.click(
'#AccessibleNav > #SiteNav > .site-nav--active > .site-nav__link > .site-nav__label'
);
await navigationPromise;
// 14. 2nd page in collection
await page.waitForSelector(
'div > #Collection > .list--inline > li:nth-child(3) > .btn'
);
await page.click(
'div > #Collection > .list--inline > li:nth-child(3) > .btn'
);
await navigationPromise;
// 15. 3rd page in collection
await page.waitForSelector(
'#Collection > .list--inline > li > .btn > .icon-arrow-right'
);
await page.click(
'#Collection > .list--inline > li > .btn > .icon-arrow-right'
);
await navigationPromise;
// 16. last product in collection
await page.waitForSelector(
'#Collection > .grid > .grid__item:nth-child(4) > .grid-view-item > .grid-view-item__link'
);
await page.click(
'#Collection > .grid > .grid__item:nth-child(4) > .grid-view-item > .grid-view-item__link'
);
await navigationPromise;
endTime = new Date();
console.log('Shopify test time: ', runTime(startTime, endTime) + 'sec');
} catch (e) {
console.error(e);
}
};
module.exports = shopifyTest;