質問

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?

役に立ちましたか?

解決 4

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.

他のヒント

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.com'),

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

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


browser2
    .setValue('#js-command-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.com/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.com');
   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!');
});

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top