-
Notifications
You must be signed in to change notification settings - Fork 3
/
loadtest_synthetic.js
92 lines (73 loc) · 3.61 KB
/
loadtest_synthetic.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
// Test Site
const test_url = 'https://dev-accelerated-store-demo.pantheonsite.io';
// Exports
module.exports = { runTest }
// Include Puppeteer
const puppeteer = require( '/usr/local/lib/node_modules/puppeteer' );
// Increase Event Listeners
process.setMaxListeners( 0 );
// Test Function
async function runTest( context, events, next ) {
// Start Counter
var counter_start = new Date();
var counter_start_ms = ( counter_start.getTime() + '.' + counter_start.getMilliseconds() );
context.vars.counter_start_ms = counter_start_ms;
const browser = await puppeteer.launch( { headless: true } );
const page = await browser.newPage();
const payload_qty = context.vars.quantity.toString();
const payload_productid = context.vars.product_id;
const payload_name = context.vars.name;
await page.setViewport( { width: 1280, height: 1280 } )
try {
// Adding To Cart
console.log( '1 - Adding To Cart & Redirecting Checkout' );
await page.goto( test_url + '/checkout/?add-to-cart=' + payload_productid, { 'waitUntil' : 'networkidle0', timeout: 0 } );
await page.waitForSelector( 'button#place_order', { timeout: 0 } );
// Complete Checkout Form
console.log( '2 - Completing Checkout Form Fields' );
await page.evaluate( ( payload_name ) => { document.querySelector( 'input#billing_email' ).value = payload_name + '@codedcommerce.com' }, payload_name );
await page.evaluate( ( payload_name ) => { document.querySelector( 'input#billing_first_name' ).value = payload_name }, payload_name );
await page.evaluate( ( payload_name ) => { document.querySelector( 'input#billing_last_name' ).value = payload_name }, payload_name );
await page.evaluate( () => { document.querySelector( 'input#billing_address_1' ).value = '12345 Test St.' } );
await page.evaluate( () => { document.querySelector( 'input#billing_city' ).value = 'Los Angeles' } );
await page.evaluate( () => { document.querySelector( 'input#billing_postcode' ).value = '91307' } );
await page.evaluate( () => { document.querySelector( 'input#billing_phone' ).value = '111-222-3333' } );
await page.waitForSelector( 'button#place_order', { timeout: 0 } );
// State Drop Down
console.log( '3 - Selecting State Drop Down' );
await page.select( 'select#billing_state', 'CA' );
await page.waitForSelector( 'button#place_order', { timeout: 0 } );
// Complete Payment Method
await page.waitFor( 1000 );
console.log( '4 - Selecting COD Payment' );
await page.click( "label[for='payment_method_cod']" );
await page.waitForSelector( 'button#place_order', { timeout: 0 } );
// Submit Checkout
await page.waitFor( 1000 );
console.log( '5 - Clicking Place Order Button' );
await page.click( 'button#place_order' );
await page.waitForSelector( 'li.order', { timeout: 0 } );
// Order Receipt
console.log( '6 - Parsing Order Receipt' );
context.vars.order_number = await page.evaluate(
() => document.querySelector( 'li.order strong' ).textContent
);
console.log( '7 - Order placed: ' + context.vars.order_number.trim() );
// Screen Shot
//await page.screenshot( { path: order_number.trim() + '.png', fullPage: true } );
// Catch Errors
} catch( err ) {
console.log( err );
await page.screenshot( { path: 'error-' + context.vars.counter_start_ms + '.png', fullPage: true } );
}
// Close Browser
await browser.close();
// End Counter
var counter_stop = new Date();
var counter_stop_ms = ( counter_stop.getTime() + '.' + counter_stop.getMilliseconds() );
context.vars.lapsed = Math.round( counter_stop_ms - counter_start_ms );
// Process Latency
events.emit( 'histogram', 'HeadlessChromiumLatency', context.vars.lapsed );
// Return
return next();
}