Skip to content

Commit ac2a476

Browse files
committed
Bugfixes on invalid variable name.
1 parent 1a64b58 commit ac2a476

File tree

4 files changed

+61
-30
lines changed

4 files changed

+61
-30
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 1.2.8 (2016.01.31)
2+
3+
* Bugfixes on issue #6
4+
15
### 1.2.7 (2016.01.19)
26

37
* Update copyright year
@@ -14,7 +18,7 @@
1418

1519
### 1.2.5 (2015.09.22)
1620

17-
* Bugfixes
21+
* Bugfixes on issue #3
1822

1923
### 1.2.4 (2015.08.28)
2024

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "selenium-page-object-generator",
3-
"version": "1.2.7",
3+
"version": "1.2.8",
44
"description": "A nimble and flexible Selenium Page Object Model generator to improve agile testing process velocity.",
55
"dependencies": {
66
"argparse": "^1.0.4",

specs/issues/006.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
</head>
5+
<body>
6+
<label id="LS1.0Q1.0" for="S1.0Q1.0" class="LC1"><b>1.1</b> What is the legal name of your Company?</label><br/>
7+
<input id="S1.0Q1.0" name="S1.0Q1.0" class="Answered" value="11b" required type="text"/>
8+
<!--
9+
[FindsBy(How = How.Id, Using = "S1.0Q1.0")]
10+
[CacheLookup]
11+
private IWebElement 11WhatIsTheLegalName;
12+
-->
13+
</body>
14+
</html>

src/common/generator.js

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ window.POG=(function() {
8888
currentSelector += '[type=\'' + node.type + '\']';
8989
}
9090
else if (node.getAttribute('data-type')) {
91-
currentSelector += '[data-type=\'' + node.getAttribute('data-type') + '\']';
91+
currentSelector += '[data-type=\'' +
92+
node.getAttribute('data-type') + '\']';
9293
}
9394
}
9495
}
@@ -134,7 +135,7 @@ window.POG=(function() {
134135
buffer.operation.documentation = input.action + suffixes.action +
135136
suffixes.documentation;
136137
buffer.operation.name = getLetter(input.action + suffixes.name,
137-
input.letters.operation);
138+
input.letters.operation, input.action);
138139

139140
return buffer;
140141
}
@@ -147,12 +148,11 @@ window.POG=(function() {
147148
var clones = cloned.getElementsByTagName('*');
148149
var originals = original.getElementsByTagName('*');
149150
var hiddens = (cloned) ? Array.filter(cloned.querySelectorAll(
150-
'*:not(br):not(img):not(input):not(link):not(option):not(script):not(select):not(style)'),
151-
function(item, index) {
152-
var sourceIndex = [].indexOf.call(clones, item);
153-
return originals[sourceIndex].offsetHeight < 1 ||
154-
!isElementInViewport(item);
155-
}) : [];
151+
'*:not(br):not(img):not(input):not(link):not(option):not(script):not(select):not(style)'
152+
), function(item, index) {
153+
var sourceIndex = [].indexOf.call(clones, item);
154+
return originals[sourceIndex].offsetHeight < 1 || !isElementInViewport(item);
155+
}) : [];
156156
return hiddens;
157157
}
158158

@@ -214,33 +214,42 @@ window.POG=(function() {
214214
return text;
215215
}
216216

217-
function getLetter(value, type) {
217+
function getLetter(value, type, action) {
218+
action = action || '';
218219
type = type || LETTERS.CAMEL;
219220
type = parseInt(type);
220221
value = value || '';
221222

223+
if (type !== LETTERS.NATURAL) {
224+
// move number prefix to the end of the value
225+
var oldValue = value.replace(action, '').trim();
226+
var numberPrefix = /^([\d.]+)/.exec(oldValue);
227+
if (numberPrefix) {
228+
value = value.replace(numberPrefix[0], '') + ' ' + numberPrefix[0];
229+
}
230+
}
231+
222232
switch (type) {
223233
case LETTERS.LOWER:
224234
case LETTERS.UPPER:
225235
value = value.replace(/\./g, '_').replace(/\s+|__/g, '_').replace(/^_|_$/g, '');
226236
value = (type === LETTERS.LOWER) ? value.toLowerCase() : value.toUpperCase();
227237
break;
228238
case LETTERS.CAMEL:
229-
case LETTERS.NATURAL:
230239
case LETTERS.PROPER:
231240
value = value.replace(/\./g, ' ').trim().replace(/\s\s+/g, ' ').
232241
replace(/\w\S*/g, function(word) {
233242
return word.charAt(0).toUpperCase() + word.substr(1).toLowerCase();
234-
});
235-
236-
if (type === LETTERS.CAMEL || type === LETTERS.PROPER) {
237-
value = value.replace(/\s+/g, '');
238-
239-
if (type === LETTERS.CAMEL) {
240-
value = value.charAt(0).toLowerCase() + value.substr(1);
241-
}
243+
}).replace(/\s+/g, '');
244+
if (type === LETTERS.CAMEL) {
245+
value = value.charAt(0).toLowerCase() + value.substr(1);
242246
}
243247
break;
248+
case LETTERS.NATURAL:
249+
value = value.trim().replace(/\s\s+/g, ' ').replace(/\w\S*/g, function(word) {
250+
return word.charAt(0).toUpperCase() + word.substr(1).toLowerCase();
251+
});
252+
break;
244253
}
245254

246255
return value;
@@ -438,7 +447,9 @@ window.POG=(function() {
438447
}
439448

440449
// desc
441-
sentences.sort(function(a, b) { return sentences.frequencies[b] - sentences.frequencies[a]; });
450+
sentences.sort(function(a, b) {
451+
return sentences.frequencies[b] - sentences.frequencies[a];
452+
});
442453

443454
return sentences;
444455
}
@@ -450,11 +461,12 @@ window.POG=(function() {
450461
words.frequencies = {};
451462
words.tops = [];
452463

453-
text.toLowerCase().split(/[\s*\.*\,\;\+?\#\|:\-\/\\\[\]\(\)\{\}$%&0-9*]/).map(function(k, v) {
454-
if (k && k.length > 1) {
455-
words.frequencies[k]++ || (words.frequencies[k] = 1);
456-
}
457-
});
464+
text.toLowerCase().split(/[\s*\.*\,\;\+?\#\|:\-\/\\\[\]\(\)\{\}$%&0-9*]/).
465+
map(function(k, v) {
466+
if (k && k.length > 1) {
467+
words.frequencies[k]++ || (words.frequencies[k] = 1);
468+
}
469+
});
458470

459471
for (var word in words.frequencies) {
460472
words[++index] = word;
@@ -588,10 +600,11 @@ window.POG=(function() {
588600
submit.label = label;
589601
submit.text = text;
590602
}
591-
else if (submit.text === '' && text.toLowerCase().indexOf('submit') > -1) {
592-
submit.label = label;
593-
submit.text = text;
594-
}
603+
else if (submit.text === '' && text.toLowerCase().
604+
indexOf('submit') > -1) {
605+
submit.label = label;
606+
submit.text = text;
607+
}
595608
}
596609
else {
597610
if (inputType === 'hidden') {

0 commit comments

Comments
 (0)