2

I have to invoke a js file from spec file

below is sample files

spec file

 @script highlight.js

 @objects
    header              xpath   /html/body/app/mbx-header/div

 = Verify the focus of header button =
 header:
    text is "${highlight()}" 
    ${click('//some/xpath')}
    css box-shadow is "rgb(233, 238, 206)"

highlight.js

this.highlight = function () {
return 'test123';
};

click.js

this.click = function (xpath) {
//code to click element
};

Actually in the above code validation of text works but is there a way to click on element using js. is there a way to inject js file in the spec file to click on a element during execution and then verify the properties i'm new to java script and Galen .

Vysh
  • 45
  • 6
  • to achieve this you have to write custom rules, see http://galenframework.com/docs/reference-galen-spec-language-guide/#CustomRulesJavaScriptbasedrules – hypery2k Apr 20 '17 at 13:56
  • 1
    @hypery2k document.getElementById("btn-0").click(); works fine in crome browser but on adding it it Js file and executing from galen its throwing 'org.mozilla.javascript.EcmaError: ReferenceError: "document" is not defined. error' – Vysh Apr 21 '17 at 13:10
  • please post your complete code so that I can have a look at it – hypery2k Apr 24 '17 at 07:51
  • @hypery2k please check this https://groups.google.com/forum/#!topic/galen-framework/pRVG3A6dXzI – Vysh Apr 24 '17 at 11:55

1 Answers1

0

Galen Spec files are more into HTML and CSS rather than performing actions. To inject Javascript in the middle of the execution you need to create a test.js file.

Here is an example:

test("Inject Javascript", function () {
  var driver = createDriver("http://website_url_goes_here", "640x480");
  inject(driver,"your javascript code here");
  checkLayout(driver, "yourspec.gspec");
});

Hope this helps.

anothernode
  • 5,100
  • 13
  • 43
  • 62
Raj Sahoo
  • 488
  • 6
  • 11