Difference between revisions of "Advancedcommands"
From Autodrive
m (→Accessing Automation Thread (ADbase)) |
(→Error handling) |
||
Line 9: | Line 9: | ||
===Error handling=== | ===Error handling=== | ||
<nowiki> | <nowiki> | ||
+ | /* | ||
+ | * This catches all exceptions from javascript and java, only exception is script errors | ||
+ | */ | ||
SCRIPT:javascript | SCRIPT:javascript | ||
try { | try { | ||
var s = 'Plain javascript string variable'; | var s = 'Plain javascript string variable'; | ||
+ | } catch (err) { | ||
+ | // do something | ||
+ | } | ||
+ | ENDSCRIPT</nowiki> | ||
+ | |||
+ | <nowiki> | ||
+ | /* | ||
+ | * The following error is not caught. The script error is caught by the automation driver and | ||
+ | * reported, which can be seen from the htmlreport | ||
+ | */ | ||
+ | SCRIPT:javascript | ||
+ | try { | ||
+ | var s = '''; | ||
} catch (err) { | } catch (err) { | ||
// do something | // do something |
Revision as of 11:12, 2 April 2013
This chapter shows how to create advanced commands. Below are a few examples on aspects opening up for programming advanced commands in Java and JavaScript. Only imagination limits its use.
Contents
Plain scripting language usage
SCRIPT:javascript var s = 'Plain javascript string variable'; ENDSCRIPT
Error handling
/* * This catches all exceptions from javascript and java, only exception is script errors */ SCRIPT:javascript try { var s = 'Plain javascript string variable'; } catch (err) { // do something } ENDSCRIPT
/* * The following error is not caught. The script error is caught by the automation driver and * reported, which can be seen from the htmlreport */ SCRIPT:javascript try { var s = '''; } catch (err) { // do something } ENDSCRIPT
Accessing Automation Thread (ADbase)
This is a very powerful feature, which makes it possible to be cost-effective when automating things. Modularization has to be chosen carefully, though.
/* * The main automation thread at exposes all public methods on the ADbase thread object, see javadoc * * This example loads defined javascript functions from a file named stdfunc.js * located in the project root folder. */ SCRIPT:javascript importPackage( Packages.dk.autodrive.base ); var f = ''+at.loadJS("stdfunc.js"); eval(f); ENDSCRIPT
Calling Java class
SCRIPT:javascript importPackage( Packages.dk.autodrive.util ); ResultWriter rw = new ResultWriter(); rw.println("Test message to default result.txt file in the root of the project"); rw.close(); ENDSCRIPT
Calling plugin
/* * theObj exposes all public methods on the plugin, see javadoc */ SCRIPT:javascript importPackage( Packages.dk.autodrive.base ); importPackage( Packages.dk.autodrive.plugins ); var f = ''+at.loadJS("stdfunc.js"); eval(f); theObj = getPlugin(Packages.dk.autodrive.plugins.AD_Webservice_Commands); ENDSCRIPT