Repository: elastic/synthetics
Pull request #260 (2021-04-22 15:07:06)

chore: update playwright to latest
+ part of #61 
+ Keeping it updated to be released as part of beta. 


Patch:
diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile
index cf7fd1d..92c6854 100644
--- a/.ci/Jenkinsfile
+++ b/.ci/Jenkinsfile
@@ -119,6 +119,7 @@ pipeline {
       }
     }
     stage('E2e Test') {
+      agent { label 'ubuntu-18 && immutable' }
       environment {
         E2E_FOLDER = "__tests__/e2e"
       }
diff --git a/package-lock.json b/package-lock.json
index 60ba74a..e2fec36 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4780,9 +4780,9 @@
       }
     },
     "playwright-chromium": {
-      "version": "1.8.0",
-      "resolved": "https://registry.npmjs.org/playwright-chromium/-/playwright-chromium-1.8.0.tgz",
-      "integrity": "sha512-DMyWmFPXkW0Tm5yBx2pV3m5F8qBSk29+DuZd21liwnG8qNZX43zEY1QpsS51zWPYFgi+nHkRr343GycyAoSUzQ==",
+      "version": "1.10.0",
+      "resolved": "https://registry.npmjs.org/playwright-chromium/-/playwright-chromium-1.10.0.tgz",
+      "integrity": "sha512-ry/60/YKGJfrnaS7j5C3+xmA2DAMv6pBE351FoTHe4Llq0WU92IL0rBYK3TkK3PzSHYtp1KdCRsRjDnJhImA3g==",
       "requires": {
         "commander": "^6.1.0",
         "debug": "^4.1.1",
@@ -4795,6 +4795,7 @@
         "proper-lockfile": "^4.1.1",
         "proxy-from-env": "^1.1.0",
         "rimraf": "^3.0.2",
+        "stack-utils": "^2.0.3",
         "ws": "^7.3.1"
       },
       "dependencies": {
@@ -5801,7 +5802,6 @@
       "version": "2.0.3",
       "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.3.tgz",
       "integrity": "sha512-gL//fkxfWUsIlFL2Tl42Cl6+HFALEaB1FU76I/Fy+oZjRreP7OPMXFlGbxM7NQsI0ZpUfw76sHnv0WNYuTb7Iw==",
-      "dev": true,
       "requires": {
         "escape-string-regexp": "^2.0.0"
       },
@@ -5809,8 +5809,7 @@
         "escape-string-regexp": {
           "version": "2.0.0",
           "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz",
-          "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==",
-          "dev": true
+          "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w=="
         }
       }
     },
diff --git a/package.json b/package.json
index 71a7338..9f8b142 100644
--- a/package.json
+++ b/package.json
@@ -41,7 +41,7 @@
     "commander": "^7.0.0",
     "http-proxy": "^1.18.1",
     "kleur": "^4.1.3",
-    "playwright-chromium": "=1.8.0",
+    "playwright-chromium": "=1.10.0",
     "snakecase-keys": "^3.2.1",
     "sonic-boom": "^1.3.0",
     "source-map-support": "^0.5.19",
diff --git a/src/core/runner.ts b/src/core/runner.ts
index bfd338f..10c7a2c 100644
--- a/src/core/runner.ts
+++ b/src/core/runner.ts
@@ -180,6 +180,18 @@ export default class Runner {
     log(`Runner: start step (${step.name})`);
     const { metrics, screenshots } = options;
     const { driver, pluginManager } = context;
+    /**
+     * URL needs to be the first navigation request of any step
+     * Listening for request solves the case where `about:blank` would be
+     * reported for failed navigations
+     */
+    const captureUrl = req => {
+      if (!data.url && req.isNavigationRequest()) {
+        data.url = req.url();
+      }
+      driver.page.off('request', captureUrl);
+    };
+    driver.page.on('request', captureUrl);
     try {
       pluginManager.onStep(step);
       await step.callback();
@@ -190,7 +202,7 @@ export default class Runner {
       data.status = 'failed';
       data.error = error;
     } finally {
-      data.url = driver.page.url();
+      data.url ??= driver.page.url();
       if (screenshots) {
         await driver.page.waitForLoadState('load');
         data.screenshot = (await driver.page.screenshot()).toString('base64');


Test patch:
diff --git a/__tests__/core/runner.test.ts b/__tests__/core/runner.test.ts
index 49ce1ff..ed9bfb0 100644
--- a/__tests__/core/runner.test.ts
+++ b/__tests__/core/runner.test.ts
@@ -189,6 +189,45 @@ describe('runner', () => {
     ]);
   });
 
+  it('run step - navigation failure', async () => {
+    const url = 'http://blah/';
+    const j1 = journey('j1', async ({ page }) => {
+      step('cannot resoslve url', async () => {
+        await page.goto(url);
+      });
+    });
+    const context = await Runner.createContext({});
+    await runner.registerJourney(j1, context);
+    const result = await runner.runSteps(j1, context, {});
+    await Gatherer.dispose(context.driver);
+    expect(result).toEqual([
+      {
+        status: 'failed',
+        url,
+        error: expect.any(Error),
+      },
+    ]);
+  });
+
+  it('run step - bad navigation', async () => {
+    const j1 = journey('j1', async ({ page }) => {
+      step('bad url', async () => {
+        await page.goto('blah');
+      });
+    });
+    const context = await Runner.createContext({});
+    await runner.registerJourney(j1, context);
+    const result = await runner.runSteps(j1, context, {});
+    await Gatherer.dispose(context.driver);
+    expect(result).toEqual([
+      {
+        status: 'failed',
+        url: 'about:blank',
+        error: expect.any(Error),
+      },
+    ]);
+  });
+
   it('run steps - accumulate results', async () => {
     const error = new Error('broken step 2');
     const j1 = journey('j1', async ({ page }) => {