<commit_before>/*global it:true */
"use strict";

var describeWd = require("../../helpers/driverblock.js").describeForApp('UICatalog')
  , should = require('should');

describeWd('findElementFromElement', function(h) {
  it('should find an element within itself', function(done) {
    h.driver.elementByTagName('tableView', function(err, element) {
      should.exist(element.value);
      element.elementByTagName('text', function(err, staticText) {
        should.exist(staticText.value);
        staticText.text(function(err, text) {
          text.should.equal("Buttons, Various uses of UIButton");
          done();
        });
      });
    });
  });
  it('should not find an element not within itself', function(done) {
    h.driver.elementByTagName('tableView', function(err, element) {
      should.exist(element.value);
      element.elementByTagName('navigationBar', function(err, label) {
        should.exist(err);
        done();
      });
    });
  });
});


describeWd('findElementsFromElement', function(h) {
  it('should find some elements within itself', function(done) {
    h.driver.elementByTagName('tableCell', function(err, element) {
      should.exist(element.value);
      element.elementsByTagName('text', function(err, els) {
        els.length.should.equal(1);
        done();
      });
    });
  });
  it('should not find elements not within itself', function(done) {
    h.driver.elementByTagName('tableCell', function(err, element) {
      should.exist(element.value);
      element.elementsByTagName('navigationBar', function(err, els) {
        els.length.should.equal(0);
        done();
      });
    });
  });
});


describeWd('findElementsByTagName', function(h) {
  it('should return all image elements with internally generated ids', function(done) {
    h.driver.elementsByTagName('image', function(err, elements) {
      for (var i=0; i < elements.length; i++) {
        var num = parseInt(elements[i].value, 10);
        should.exist(num);
      }
      done();
    });
  });
});

var setupXpath = function(d, cb) {
  d.elementsByTagName('tableCell', function(err, els) {
    els[0].click(cb);
  });
};

describeWd('findElement(s)ByXpath', function(h) {
  it('should return a single element', function(done) {
    setupXpath(h.driver, function() {
      h.driver.elementByXPath("//button", function(err, el) {
        should.not.exist(err);
        el.text(function(err, text) {
          should.not.exist(err);
          text.should.equal("Back");
          done();
        });
      });
    });
  });
  it('should return multiple elements', function(done) {
    setupXpath(h.driver, function() {
      h.driver.elementsByXPath("//button", function(err, els) {
        should.not.exist(err);
        els.length.should.be.above(5);
        done();
      });
    });
  });
  it.only('should filter by name', function(done) {
    setupXpath(h.driver, function() {
      h.driver.elementByXPath("button[@name='Rounded']", function(err, el) {
        should.not.exist(err);
        el.text(function(err, text) {
          should.not.exist(err);
          text.should.equal("Rounded");
          done();
        });
      });
    });
  });
});<commit_msg>initial searching by xpath logic<commit_after>/*global it:true */
"use strict";

var describeWd = require("../../helpers/driverblock.js").describeForApp('UICatalog')
  , should = require('should');

describeWd('findElementFromElement', function(h) {
  it('should find an element within itself', function(done) {
    h.driver.elementByTagName('tableView', function(err, element) {
      should.exist(element.value);
      element.elementByTagName('text', function(err, staticText) {
        should.exist(staticText.value);
        staticText.text(function(err, text) {
          text.should.equal("Buttons, Various uses of UIButton");
          done();
        });
      });
    });
  });
  it('should not find an element not within itself', function(done) {
    h.driver.elementByTagName('tableView', function(err, element) {
      should.exist(element.value);
      element.elementByTagName('navigationBar', function(err, label) {
        should.exist(err);
        done();
      });
    });
  });
});


describeWd('findElementsFromElement', function(h) {
  it('should find some elements within itself', function(done) {
    h.driver.elementByTagName('tableCell', function(err, element) {
      should.exist(element.value);
      element.elementsByTagName('text', function(err, els) {
        els.length.should.equal(1);
        done();
      });
    });
  });
  it('should not find elements not within itself', function(done) {
    h.driver.elementByTagName('tableCell', function(err, element) {
      should.exist(element.value);
      element.elementsByTagName('navigationBar', function(err, els) {
        els.length.should.equal(0);
        done();
      });
    });
  });
});


describeWd('findElementsByTagName', function(h) {
  it('should return all image elements with internally generated ids', function(done) {
    h.driver.elementsByTagName('image', function(err, elements) {
      for (var i=0; i < elements.length; i++) {
        var num = parseInt(elements[i].value, 10);
        should.exist(num);
      }
      done();
    });
  });
});

var setupXpath = function(d, cb) {
  d.elementsByTagName('tableCell', function(err, els) {
    els[0].click(cb);
  });
};

describeWd('findElement(s)ByXpath', function(h) {
  it('should return a single element', function(done) {
    setupXpath(h.driver, function() {
      h.driver.elementByXPath("//button", function(err, el) {
        should.not.exist(err);
        el.text(function(err, text) {
          should.not.exist(err);
          text.should.equal("Back");
          done();
        });
      });
    });
  });
  it('should return multiple elements', function(done) {
    setupXpath(h.driver, function() {
      h.driver.elementsByXPath("//button", function(err, els) {
        should.not.exist(err);
        els.length.should.be.above(5);
        done();
      });
    });
  });
  it('should filter by name', function(done) {
    setupXpath(h.driver, function() {
      h.driver.elementByXPath("button[@name='Rounded']", function(err, el) {
        should.not.exist(err);
        el.text(function(err, text) {
          should.not.exist(err);
          text.should.equal("Rounded");
          done();
        });
      });
    });
  });
  it.only('should search an extended path', function(done) {
    setupXpath(h.driver, function() {
      h.driver.source(function(err, s) {
        console.log(s);
        done();
      });
      //h.driver.elementByXPath("button[@name='Rounded']", function(err, el) {
        //should.not.exist(err);
        //el.text(function(err, text) {
          //should.not.exist(err);
          //text.should.equal("Rounded");
          //done();
        //});
      //});
    });
  });
});
{'fraction_non_alphanumeric': 0.17206801337014968, 'fraction_numerical': 0.002034587995930824, 'mean_word_length': 2.8597868760515985, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2544990', 'n_tokens_mistral': 2128, 'n_tokens_neox': 2117, 'n_words': 365}