Skip to content

Commit

Permalink
Bump version to 1.1.2
Browse files Browse the repository at this point in the history
- Employ better and broader mechanism to get label text
- Prepend change log file
  • Loading branch information
rickypc committed Jul 17, 2015
1 parent 83bbf50 commit a5a6783
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.1.2 (2015.07.16)

* Employ better and broader mechanism to get label text

### 1.1.1 (2015.07.14)

* Cancel default action on Options button click
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "selenium-page-object-generator",
"version": "1.1.1",
"version": "1.1.2",
"description": "A nimble and flexible Selenium Page Object Model generator to improve agile testing process velocity.",
"dependencies": {},
"devDependencies": {
Expand Down
56 changes: 47 additions & 9 deletions src/chrome/assets/js/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ window.POG=(function() {
// ========================================================================
// private functions

function getClosestSibling(node, siblings) {
var copies = siblings.slice(0);
copies.push(node);
var closest = copies.length - 1;
var nodeIndex = [].indexOf.call(copies, node);
var siblingIndex = closest;

for (var i = 0, j = copies.length; i < j; i++) {
var delta = Math.abs(nodeIndex - i);

if (delta < closest) {
closest = delta;
siblingIndex = i;
}
}

return (siblingIndex === (copies.length - 1)) ? null : copies[siblingIndex];
}

function getComments(root) {
var comments = [];
var index = -1;
Expand Down Expand Up @@ -45,7 +64,7 @@ window.POG=(function() {

if (nodeName === 'INPUT') {
if (node.getAttribute('type')) {
currentSelector += '[type=\'' + node.getAttribute('type') + '\']';
currentSelector += '[type=\'' + node.type + '\']';
}
else if (node.getAttribute('data-type')) {
currentSelector += '[data-type=\'' + node.getAttribute('data-type') + '\']';
Expand Down Expand Up @@ -121,23 +140,42 @@ window.POG=(function() {
var text = '';

if (node.id) {
label = document.querySelector('label[for="' + node.id + '"]');
text = getLabelTextFor(node.id);
}

if (label) {
text = label.textContent || label.innerText || '';
text = text.trim();
}
if (text === '' && node.name) {
// non-standard, but it happens
text = getLabelTextFor(node.name);
}

if (text === '') {
// find label from siblings
label = Array.filter([].slice.call(node.parentNode.children),
// TODO: should use more aggressive collector
labels = Array.filter([].slice.call(node.parentNode.children),
function(item, index) {
return item.nodeName === 'LABEL';
});

if (label.length) {
text = label[0].textContent || label[0].innerText || '';
var label = getClosestSibling(node, labels);

if (label) {
text = label.textContent || label.innerText || '';
text = text.trim();
}
}

return text;
}

function getLabelTextFor(identifier) {
var label = null;
var text = '';

if (identifier) {
label = document.querySelector('label[for="' + identifier + '"]');

if (label) {
text = label.textContent || label.innerText || '';
text = text.trim();
}
}
Expand Down

0 comments on commit a5a6783

Please sign in to comment.