before(function(done) {
        client
            .get(test_url);

        client
            .findElement(webdriver.By.tagName("body"))
            .then(function(){done();});
    });
 it('should lead us to the game page', function(done) {
     client
         .findElement(webdriver.By.linkText("Start game"))
         .click()
         .then(function(){
             assert.ok(
                 client.findElement(webdriver.By.xpath("//input[@data-bind='value: currentExercise().result']"))
                       .then(function(){done();}));
         });
 });
var solveOneMulti = function(done){
    // Uuaagh: We cannot hold state well in this async-o-rama,
    // so I copy the factors into the result field, eval() (!!)
    // its content and send the result back to the field.

    var field = client.findElement(webdriver.By.xpath("//input[@data-bind='value: currentExercise().result']"));
    field.clear();

    client
        .findElement(webdriver.By.xpath("//span[@data-bind='text: currentExercise().factor1']"))
        .getText()
        .then(function(text) {
            field.sendKeys(text + " * ");
            //console.log(text);
        });

    client
        .findElement(webdriver.By.xpath("//span[@data-bind='text: currentExercise().factor2']"))
        .getText()
        .then(function(text) {
            field.sendKeys(text);
            //console.log(text);
        });

    field
        .getAttribute("value")
        .then(function(text) {
            var result = eval(text);
            console.log(text + " = " + result);
            field.clear();
            field.sendKeys(result);
        });

    client
        .findElement(webdriver.By.css("body"))
        .click()
        .then(function(){done();});
};
Esempio n. 4
0
// Small example of using WebdriverJS from
// http://code.google.com/p/selenium/wiki/WebDriverJs

var webdriver = require('selenium-webdriverjs');

var driver = new webdriver.Builder().
    usingServer('http://localhost:4444/wd/hub').
    withCapabilities({
      'browserName': 'firefox',
      'version': '',
      'platform': 'ANY',
      'javascriptEnabled': true
    }).
    build();

driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.getTitle().then(function(title) {
  require('assert').equal('Google', title);

});

driver.quit();

 it('should show a `Next exercise` link when correct', function(done) {
     client
         .findElement(webdriver.By.linkText("Next exercise"))
         .click()
         .then(function(){done();});
 });
 .then(function(){
     assert.ok(
         client.findElement(webdriver.By.xpath("//input[@data-bind='value: currentExercise().result']"))
               .then(function(){done();}));
 });
 it('should have a `Start game` link', function() {
     assert(client.findElement(webdriver.By.linkText("Start game")).isDisplayed());
 });