0

We recently decided to include E2E to our front-end pipeline and we are using testCafe for that and since we use AWS as our SaaS we're being asked to use Devicefarm for remote testing and I'm facing the problem to connect them. I'm based on the selenium implementations and the testCafe documentation but it seems not to be able to establish connection between them, anyone has any idea why?

My code:

const AWS = require('aws-sdk');
const createTestCafe = require('testcafe');

const PROJECT_ARN = "arn:aws:devicefarm:us-west-2:XXXXXXXX:testgrid-project:XXXXXX-XXXX-XXXX-XXXX-XXXXXXXX";
const devicefarm = new AWS.DeviceFarm({ region: "us-west-2", credentials: AWS.config.credentials });

(async () => {
    const testGridUrlResult = await devicefarm.createTestGridUrl({
        projectArn: PROJECT_ARN,
        expiresInSeconds: 6000
    }).promise();

    const url = new URL(testGridUrlResult.url || '');
    const testCafe         = await createTestCafe(url.host, 443);
    const runner           = testCafe.createRunner();
    const remoteConnection = await testCafe.createBrowserConnection();

    remoteConnection.once('ready', async () => {
        await runner
            .src(['./load-mfc.ts'])
            .browsers('devicefarm:firefox')
            .run();

        await testCafe.close();
    });

})().catch((e) => console.error(e));
Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
TurboAza
  • 75
  • 1
  • 9

1 Answers1

1

According to the AWS Device Farm documentation about the CreateTestGridUrl method:

Creates a signed, short-term URL that can be passed to a Selenium RemoteWebDriver constructor.

This URL can't be passed to the hostname property of the createTestCafe method because TestCafe doesn't implement the WebDriver protocol. TestCafe works differently then Selenium. Once you created a remote browser connection using TestCafe, you should navigate your remote browser to the browserConnection.url URL to connect to a TestCafe server instance and start test execution in this browser.

As the AWS Device Farm service uses the WebDriver protocol to operate remote browsers, you would need to write a custom Browser Provider Plugin for TestCafe. It may be helpful to read more in the TestCafe documentation about this topic and see how a similar thing is implemented in the BrowserStack provider.

wentwrong
  • 711
  • 4
  • 7