Skip to content

Adding support for Ruby and more functions #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/dictionaries/shir_cohen.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/selenium-page-object-generator.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Selenium Page Object Generator is also available in command line by installing [

The template is using [Handlebars.js](http://handlebarsjs.com/) expression, a clean logic-less semantic templating language.

This is an early BETA release, it expected to have rough edges, and limited functionality. It currently support 3 different targets: [Java](https://en.wikipedia.org/wiki/Java_(programming_language)), [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)), and [Robot Framework](http://robotframework.org/).
This is an early BETA release, it expected to have rough edges, and limited functionality. It currently support 3 different targets: [Java](https://en.wikipedia.org/wiki/Java_(programming_language)), [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)), [Ruby](https://en.wikipedia.org/wiki/Ruby_(programming_language)) and [Robot Framework](http://robotframework.org/).

For more information on how to use the generated Page Object file:

Expand All @@ -23,6 +23,8 @@ C#: [http://relevantcodes.com/pageobjects-and-pagefactory-design-patterns-in-sel

Robot Framework: [http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#taking-resource-files-into-use](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#taking-resource-files-into-use)

Ruby: [https://github.com/cheezy/page-object](https://github.com/cheezy/page-object)

(You need to use Chrome 40+ or Opera 15+ or Node.JS 5.x to try this out)

Installation
Expand All @@ -45,7 +47,7 @@ selenium-page-object-generator [options]

-h, --help Show this help message and exit.
-v, --version Show program's version number and exit.
-t, --target {cs,java,robot} Generator target
-t, --target {cs,java,robot, rb} Generator target
-n, --name [PageName] Page name (no-spaces)
-d, --destination [DestinationPageName] Destination page name (no-spaces) (optional)
-s, --source [source.html] Source file
Expand Down
5 changes: 3 additions & 2 deletions bin/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var parser = new ArgumentParser({
});

parser.addArgument(['-t', '--target'], {
choices: ['cs', 'java', 'robot'],
choices: ['cs', 'java', 'robot', 'rb'],
help: 'Generator target',
required: true
});
Expand Down Expand Up @@ -55,7 +55,8 @@ var paths = {
var targets = {
cs: { label: 'C#' },
java: { label: 'Java' },
robot: { label: 'Robot Framework' }
robot: { label: 'Robot Framework' },
rb: { label: 'Ruby' }
};

function getFileContent(path) {
Expand Down
11 changes: 11 additions & 0 deletions configs/rb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"attributes": {
"letter": 2,
"indent": 1,
"separator": "",
"customAttribute": ""
},
"operations": {
"letter": 2
}
}
52 changes: 44 additions & 8 deletions specs/common/common-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ describe('common.getStorage', function() {
targets: {
cs: { label: 'C#', config: values, template: '{{template}}' },
java: { label: 'Java', config: values, template: '{{template}}' },
robot: { label: 'Robot Framework', config: values, template: '{{template}}' }
robot: { label: 'Robot Framework', config: values, template: '{{template}}' },
rb: { label: 'Ruby', config: values, template: '{{template}}' }
}
});
});
Expand All @@ -406,7 +407,8 @@ describe('common.getStorage', function() {
handler({ targets: {
cs: { config: { timeout: 90 }, label: 'C#' },
java: { config: { timeout: 90 }, label: 'Java' },
robot: { config: { timeout: 90 }, label: 'Robot Framework' }
robot: { config: { timeout: 90 }, label: 'Robot Framework' },
rb: { config: { timeout: 90 }, label: 'Ruby' }
} });
});
var response = common.common.getStorage();
Expand All @@ -428,7 +430,8 @@ describe('common.getStorage', function() {
targets: {
cs: { label: 'C#', config: values, template: '{{template}}' },
java: { label: 'Java', config: values, template: '{{template}}' },
robot: { label: 'Robot Framework', config: values, template: '{{template}}' }
robot: { label: 'Robot Framework', config: values, template: '{{template}}' },
rb: { label: 'Ruby', config: values, template: '{{template}}' }
}
});
});
Expand All @@ -448,7 +451,8 @@ describe('common.getStorage', function() {
handler({ targets: {
cs: { label: 'C#', template: '{{cached}}' },
java: { label: 'Java', template: '{{cached}}' },
robot: { label: 'Robot Framework', template: '{{cached}}' }
robot: { label: 'Robot Framework', template: '{{cached}}' },
rb: { label: 'Robot Framework', template: '{{cached}}' }
} });
});
var response = common.common.getStorage();
Expand All @@ -470,7 +474,8 @@ describe('common.getStorage', function() {
targets: {
cs: { label: 'C#', config: values, template: '{{cached}}' },
java: { label: 'Java', config: values, template: '{{cached}}' },
robot: { label: 'Robot Framework', config: values, template: '{{cached}}' }
robot: { label: 'Robot Framework', config: values, template: '{{cached}}' },
rb: { label: 'Ruby', config: values, template: '{{cached}}' }
}
});
});
Expand Down Expand Up @@ -507,7 +512,8 @@ describe('common.getStorage', function() {
targets: {
cs: { label: 'C#' },
java: { label: 'Java' },
robot: { label: 'Robot Framework' }
robot: { label: 'Robot Framework' },
rb: { label: 'Ruby' }
}
});
});
Expand Down Expand Up @@ -548,7 +554,8 @@ describe('common.getStorage', function() {
targets: {
cs: { label: 'C#', template: '{{template}}' },
java: { label: 'Java', template: '{{template}}' },
robot: { label: 'Robot Framework', template: '{{template}}' }
robot: { label: 'Robot Framework', template: '{{template}}' },
rb: { label: 'Ruby', template: '{{template}}' }
}
});
});
Expand Down Expand Up @@ -590,7 +597,8 @@ describe('common.getStorage', function() {
targets: {
cs: { config: values, label: 'C#' },
java: { config: values, label: 'Java' },
robot: { config: values, label: 'Robot Framework' }
robot: { config: values, label: 'Robot Framework' },
rb: { config: values, label: 'Ruby' }
}
});
});
Expand Down Expand Up @@ -667,6 +675,16 @@ describe('common.setDefaultValues', function() {
attributes.indent).toBeTruthy();
});

it('should set attributes name format to false', function() {
expect(common.common.setDefaultValues().attributes.nameFormat).toBeFalsy();
});


it('should set attributes name format to input value', function() {
expect(common.common.setDefaultValues({ attributes: { nameFormat: true } }).
attributes.nameFormat).toBeTruthy();
});

it('should set attributes separator to breakline', function() {
expect(common.common.setDefaultValues().attributes.separator).toEqual('\n');
});
Expand All @@ -676,6 +694,15 @@ describe('common.setDefaultValues', function() {
attributes.separator).toEqual('a');
});

it('should set attributes custom attribute to breakline', function() {
expect(common.common.setDefaultValues().attributes.customAttribute).toEqual('\n');
});

it('should set attributes custom attribute input value', function() {
expect(common.common.setDefaultValues({ attributes: { customAttribute: 'data-automations' } }).
attributes.customAttribute).toEqual('data-automations');
});

it('should set copyright hash', function() {
expect({}.toString.call(common.common.setDefaultValues().copyright)).
toEqual('[object Object]');
Expand Down Expand Up @@ -849,6 +876,15 @@ describe('common.setDefaultValues', function() {
operations.extras['verify.url']).toEqual(0);
});

it('should set operation extras goto.page to default value', function() {
expect(common.common.setDefaultValues().operations.extras['goto.page']).toEqual(1);
});

it('should set operations extras goto.page to input value', function() {
expect(common.common.setDefaultValues({ operations: { extras: { 'goto.page': 0 } } }).
operations.extras['verify.url']).toEqual(0);
});

it('should set operations letter to camel case', function() {
expect(common.common.setDefaultValues().operations.letter).toEqual(common.LETTERS.CAMEL);
});
Expand Down
1 change: 1 addition & 0 deletions src/chrome/assets/css/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ fieldset label[for='model.include'],
fieldset label[for='nodes.angular'],
fieldset label[for^='operations.fill'],
fieldset label[for='operations.submit'],
fieldset label[for='operations.goto.page'],
fieldset label[for^='operations.verify'] {
width: 300px;
}
Expand Down
20 changes: 18 additions & 2 deletions src/chrome/assets/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ function getElements() {
attributes: {
indent: $('[id="attributes.indent"]'),
letter: $('[id="attributes.letter"]'),
separator: $('[id="attributes.separator"]')
separator: $('[id="attributes.separator"]'),
nameFormat: $('[id="attributes.nameFormat"]'),
customAttribute: $('[id="attributes.customAttribute"]')
},
copyright: {
claimant: $('[id="copyright.claimant"]'),
Expand All @@ -29,7 +31,8 @@ function getElements() {
'fill.submit': $('[id="operations.fill.submit"]'),
submit: $('[id="operations.submit"]'),
'verify.loaded': $('[id="operations.verify.loaded"]'),
'verify.url': $('[id="operations.verify.url"]')
'verify.url': $('[id="operations.verify.url"]'),
'goto.page': $('[id="operations.goto.page"]')
},
letter: $('[id="operations.letter"]'),
separator: $('[id="operations.separator"]')
Expand Down Expand Up @@ -72,7 +75,9 @@ function pull(elements, target) {
}

target.config.attributes.indent = elements.attributes.indent.get(0).checked;
target.config.attributes.nameFormat = elements.attributes.nameFormat.get(0).checked;
target.config.attributes.letter = elements.attributes.letter.val();
target.config.attributes.customAttribute = elements.attributes.customAttribute.val();
target.config.attributes.separator = elements.attributes.separator.val().
replace(/\\n/g, '\n');

Expand All @@ -90,6 +95,9 @@ function pull(elements, target) {
target.config.nodes.selector = elements.nodes.selector.val();
target.config.nodes.visibility = elements.nodes.visibility.val();

/*
set the default value of the options in the popup options to be checked
*/
target.config.operations.extras.fill = elements.operations.extras.fill.
get(0).checked;
target.config.operations.extras['fill.submit'] = elements.operations.
Expand All @@ -100,6 +108,8 @@ function pull(elements, target) {
extras['verify.loaded'].get(0).checked;
target.config.operations.extras['verify.url'] = elements.operations.
extras['verify.url'].get(0).checked;
target.config.operations.extras['goto.page'] = elements.operations.
extras['goto.page'].get(0).checked;

target.config.operations.letter = elements.operations.letter.val();
target.config.operations.separator = elements.operations.separator.val().
Expand All @@ -116,10 +126,14 @@ function push(elements, target) {

elements.attributes.indent.get(0).checked = !!target.config.
attributes.indent;
elements.attributes.nameFormat.get(0).checked = !!target.config.
attributes.nameFormat;
elements.attributes.letter.val(target.config.attributes.letter);
elements.attributes.separator.val(target.config.attributes.
separator.replace(/\n/g, '\\n'));

elements.attributes.customAttribute.val(target.config.attributes.customAttribute);

elements.copyright.claimant.val(target.config.copyright.claimant);
elements.copyright.year.val(target.config.copyright.year);

Expand All @@ -146,6 +160,8 @@ function push(elements, target) {
operations.extras['verify.loaded'];
elements.operations.extras['verify.url'].get(0).checked = !!target.config.
operations.extras['verify.url'];
elements.operations.extras['goto.page'].get(0).checked = !!target.config.
operations.extras['goto.page'];

elements.operations.letter.val(target.config.operations.letter);
elements.operations.separator.val(target.config.operations.
Expand Down
9 changes: 4 additions & 5 deletions src/chrome/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"author": "",
"author": "Shir Cohen",

"browser_action": {
"default_icon": {
Expand All @@ -8,10 +8,9 @@
},
"default_popup": "popup.html"
},

"content_security_policy": "script-src 'self' 'unsafe-eval' https://www.google-analytics.com; object-src 'self'",

"description": "",
"description": "Page Object generator for Ruby",

"homepage_url": "https://github.com/rickypc/selenium-page-object-generator",

Expand All @@ -25,7 +24,7 @@

"minimum_chrome_version": "40",

"name": "",
"name": "Ruby generator",

"options_ui": {
"chrome_style": true,
Expand All @@ -40,5 +39,5 @@

"short_name": "PO Generator",

"version": ""
"version": "1.0"
}
Loading