0 votes
1 view
in Devops and Agile by (23.1k points)

Every protractor example I can find on the internet seems to use the browser.get with a web URI.

browser.get('http://localhost:8000');

I'd like to use Selenium to simply navigate to a file:// path so that I don't need a local webserver running in order to perform tests. All I need is a simple HTML page and some assets.

That doesn't seem to work though.

browser.get('file:///Users/myusername/dev/mpproject/spec/support/index.html');

When I paste that URI into my browser window I get an HTML page. When I try to open it with protractor I get a timeout. How can I run tests on this page with a protractor? The ideal answer will work with a relative file path from the myproject root.

1 Answer

0 votes
by (58.7k points)

I have had the same error, it got resolved by removing the baseUrl. Here is my setup:

protractor.config.js:

 

exports.config = {

 

  capabilities: {

    browserName: 'chrome'

  },

 

  specs: [

    '*.js'

  ],

 

  onPrepare: function() {

    // By default, Protractor use data:text/html,<html></html> as resetUrl, but 

    // location.replace from the data: to the file: protocol is not allowed

    // (we'll get ‘not allowed local resource’ error), so we replace resetUrl with the one

    // with the file: protocol (this  will open root folder of the system)

    browser.ignoreSynchronization = true;

    browser.waitForAngular();

    browser.sleep(500); 

    browser.resetUrl = 'file:///';

  }

 

};

e2etest.js:

 

'use strict';

 

describe("Buttons' tests are being started", function() {

 

    it('Must return 20 records into table', function() {

 

        browser.get('file:///C:/Users/path_to_file/index.html');

 

        /* Test codes here */

 

    });

 

});

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...