javascript - Handle two browsers concurrently with WebDriver or WebDriverJS - Stack Overflow

I am planning to test a simple realtime web app. This app is written in JavaScript and it shows the &qu

I am planning to test a simple realtime web app. This app is written in JavaScript and it shows the "presence status" of the logged in user. If the userA logs his status is being modified from "Inactive" to "Active". This action is reflected to all other users that are logged in to the application. UserB that is logged in shows realtime the presence of userA to change.

I would like to test this scenario. A test handler opens one browsers, does a write action and at the same time a second browser gets updated.

What tools are available? Can this be done with WebDriver/WebDriverJs? Can I have two threads/sessions handled via WebDriver? Any examples?

I am planning to test a simple realtime web app. This app is written in JavaScript and it shows the "presence status" of the logged in user. If the userA logs his status is being modified from "Inactive" to "Active". This action is reflected to all other users that are logged in to the application. UserB that is logged in shows realtime the presence of userA to change.

I would like to test this scenario. A test handler opens one browsers, does a write action and at the same time a second browser gets updated.

What tools are available? Can this be done with WebDriver/WebDriverJs? Can I have two threads/sessions handled via WebDriver? Any examples?

Share edited Aug 9, 2014 at 9:21 Artjom B. 62k26 gold badges135 silver badges230 bronze badges asked Oct 23, 2013 at 13:14 cateofcateof 6,78825 gold badges85 silver badges155 bronze badges 7
  • Are you not able to utilise two webdriver instances? I know that would be the simplest way to resolve this situation but obviously its not always the most suitable. – Mark Rowlands Commented Oct 23, 2013 at 13:27
  • @MarkRowlands Basically I am asking if it is doable somehow. No code written yet. – cateof Commented Oct 23, 2013 at 13:28
  • Personally, any time I've needed to perform a test like this, I took the easy way and just instantiated a second browser instance. So for example, firstDriver.findElement(By.id("doAction")).click(); assertTrue(secondDriver.findElement(By.id("resultOfAction")).isVisible()); – Mark Rowlands Commented Oct 23, 2013 at 13:32
  • any examples? tutorials? books? code? – cateof Commented Oct 23, 2013 at 13:38
  • 1 I've never used webbdriverJS myself, but a quick read of the documentation does suggest that you wouldn't need to use two separate browser instances - the use of Flows look like they could be the solution to your problem. I'm not very clued into Javascript so I'll have to bow out at this stage, sorry. – Mark Rowlands Commented Oct 23, 2013 at 14:34
 |  Show 2 more ments

4 Answers 4

Reset to default 3

You can use WebdriverJS to do that. Just create two Webdriver instances and navigate them, for example:

var WebdriverJS = require('webdriverjs'),
    assert      = require('assert'),

browser1 = new WebdriverJS({
    desiredCapabilities: {browserName:'chrome'}
}).init().url('http://github.'),

browser2 = new WebdriverJS({
    desiredCapabilities: {browserName:'chrome'}
}).init().url('http://github.');

browser1
    .setValue('#js-mand-bar-field',['webdriverjs','Enter'])
    .getText('.sort-bar h3',function(err,text) {
        assert(text.indexOf('found 24 repository results') >= 0);
    })
    .end();


browser2
    .setValue('#js-mand-bar-field',['linux','Enter'])
    .getText('.sort-bar h3',function(err,text) {
        assert(text.indexOf('We\'ve found 22,466 repository results') >= 0);
    })
    .end();

Two Chrome windows get opened and will execute your instructions independently.

With the later versions of WebDriver.js, all asynchronous operations are managed in control flows. Because the control flow will serialize all operations in the correct order, simply creating multiple driver instances may not be enough. All of the operations on one driver will occur before the operations on the other.

For true parallelization, create multiple control flows. Here is an excerpt from the documentation https://code.google./p/selenium/wiki/WebDriverJs#Defining_Multiple_Flows:

var terms = [
   'javascript',
   'selenium',
   'webdriver'
];

var flows = terms.map(function(term) {
 return webdriver.promise.createFlow(function() {
   var driver = new webdriver.Builder().build();

   driver.get('http://www.google.');
   driver.findElement(webdriver.By.name('q')).sendKeys(term);
   driver.findElement(webdriver.By.name('btnG')).click();
   driver.getTitle().then(function(title) {
     if (title !== (term + ' - Google Search')) {
       throw Error('Unexpected title: ' + title);
     }
   });
 });
});

webdriver.promise.fullyResolved(flows).then(function() {
 console.log('All tests passed!');
});

You can do it with WebDriver but if you want to run both browsers in the same machine the best way is to use different browsers so you could have two different sessions.

So try using ChromeDriver and FirefoxDriver and you will have two different sessions to test your app.

Selenium Grid option should do the trick. You will find a tutorial here which you can adapt using webdriverJS.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744913333a4600682.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信