webdriverio: Cannot get Electron's BrowserWindow URL after URL navigate

Using WebdriverIO for testing an Electron app.

I can get the current url of an Electron app’s BrowserWindow with client.url() like with any other browser. Though you cannot navigate to a URL using it since Electron uses BrowserWindow.loadUrl() to do that.

# get current URL
var webdriverio = require('webdriverio');
# set Electron option
var options = {
    host: "localhost",
    port: 9515,
    desiredCapabilities:{
      browserName: 'chrome',
      chromeOptions: {
        binary: 'Electron.app/Contents/MacOS/Electron'
      }
    }
  };

var client = webdriverio.remote(options);
client.init();

client.url(function(err, res){
    console.log(res.value);
});

But the problem is that if Electron client navigates to a remote URL (like https://github.com/) using BrowserWindow.loadUrl() internally due to some event (like button click), then the Webdriver client does not proceed to next chained action.

client
  .click('#some_btn_to_load_remote_url')
  .url(function(err, res){
      # Problem! Cannot reach here.
  })

The Electron client uses ipc.send() to handle event and the event handler is as below.


ipc.on('loadUrl', function(event, url){
    mainWindow.loadUrl(url);
});

I didn’t send back ipc reply since the caller window would not get the reply anyway.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

@lseongjoo Just stumbling on this now. Is there a safe/expected way of accessing the URL of a remote URL of a BrowserWindow instance?