Custom commands

1 view
Skip to first unread message

Clément Beaujoin

unread,
Mar 30, 2009, 11:04:40 AM3/30/09
to CubicEx-discuss
Hi, this a selection of custom commands I'm using in my tests that you
could add to the library.

--------------------------------------------------------------------------------------------------------

public class SelectMainWindow extends CubicExBaseTestCase {

private Log log = LogFactory.getLog(SelectMainWindow.class);

/**
* {@inheritDoc}
*/
public void executeTest(final Map<String, String> arguments, final
IElementContext context, final Selenium selenium) throws Exception {

if (log.isInfoEnabled()) {
log.info("SelectMainWindow: target 'null'.");
}

selenium.selectWindow("null");
}
}

--------------------------------------------------------------------------------------------------------

public class SelectWindowByLevel extends CubicExBaseTestCase {

private Log log = LogFactory.getLog(SelectWindowByLevel.class);

/**
* {@inheritDoc}
*/
public void executeTest(final Map<String, String> arguments, final
IElementContext context, final Selenium selenium) throws Exception {

// Retrieve the parameters.
final Integer _level = getArgValueAsInteger();

if (log.isInfoEnabled()) {
log.info("SelectWindowByLevel: level '" + _level + "'.");
}
String[] windowsName = selenium.getAllWindowNames();
selenium.selectWindow(windowsName[_level.intValue()]);
}
}

--------------------------------------------------------------------------------------------------------

public class SelectWindowByName extends CubicExBaseTestCase {

private Log log = LogFactory.getLog(SelectWindowByName.class);



/**
* {@inheritDoc}
*/
public void executeTest(final Map<String, String> arguments, final
IElementContext context, final Selenium selenium) throws Exception {

// Retrieve the parameters.
final String _windowsName = getArgValue();

if (log.isInfoEnabled()) {
log.info("SelectWindowByName: windowsName '" + _windowsName +
"'.");
}
selenium.selectWindow(_windowsName);
}
}

--------------------------------------------------------------------------------------------------------

public class SimulateKeyDown extends CubicExBaseTestCase {

private Log log = LogFactory.getLog(SimulateKeyDown.class);

/**
* {@inheritDoc}
*/
public void executeTest(final Map<String, String> arguments, final
IElementContext context, final Selenium selenium) throws Exception {

// Retrieve the parameters.
final String _locator = getArgTarget();
final String _keySequence = getArgValue();

if (log.isInfoEnabled()) {
log.info("SimulateKeyDown: target '" + _locator + "', keySequence
'" + _keySequence +"'.");
}
selenium.keyDown(_locator, _keySequence);
}
}

--------------------------------------------------------------------------------------------------------

public class SimulateKeyUp extends CubicExBaseTestCase {

private Log log = LogFactory.getLog(SimulateKeyUp.class);

/**
* {@inheritDoc}
*/
public void executeTest(final Map<String, String> arguments, final
IElementContext context, final Selenium selenium) throws Exception {

// Retrieve the parameters.
final String _locator = getArgTarget();
final String _keySequence = getArgValue();

if (log.isInfoEnabled()) {
log.info("SimulateKeyUp: target '" + _locator + "', keySequence '"
+ _keySequence +"'.");
}
selenium.keyUp(_locator, _keySequence);
}
}

--------------------------------------------------------------------------------------------------------

public class VerifyDate extends CubicExBaseTestCase {

private Log log = LogFactory.getLog(VerifyDate.class);

/**
* {@inheritDoc}
*/
public void executeTest(Map<String, String> arguments,
IElementContext context, Selenium selenium) throws Exception {

// Retrieve the parameters.
final String _locator = getArgTarget();
final String _format = getArgFormat();
final Integer _deviation = getArgDeviation();

if (log.isInfoEnabled()) {
log.info("VerifyDate: target '" + _locator + "', format '" +
_format + "', deviation '" + _deviation + "'.");
}

// Process the deviation
Calendar calendar = Calendar.getInstance();
calendar.roll(Calendar.DAY_OF_YEAR, _deviation);

// Create the formatted date.
final String _formattedDate = new SimpleDateFormat(_format)
.format(calendar.getTime());

// Retrieve the text.
String _textOfField = selenium.getText(_locator);

// If Text empty
if (_textOfField == null) {
// Retrieve the field value.
String _valueOfField = selenium.getValue(_locator);
verifyEquals(_valueOfField, _formattedDate);
} else {
verifyTrue(_textOfField.contains(_formattedDate));
}

}

}

--------------------------------------------------------------------------------------------------------

public class VerifyJavascriptVariable extends CubicExBaseTestCase {

private Log log = LogFactory.getLog(VerifyJavascriptVariable.class);

/**
* {@inheritDoc}
*/
public void executeTest(final Map<String, String> arguments, final
IElementContext context, final Selenium selenium) throws Exception {

final String _varName = getArgTarget();
final String _expectedValue = getArgValue();

if (log.isInfoEnabled()) {
log.info("VerifyJavascriptVariable: target '" + _varName + "',
value '" + _expectedValue +"'.");
}

//Retrieve Javascript Variable value
String _javascriptVariable = selenium.getEval
("this.browserbot.getCurrentWindow()." + _varName);

verifyEquals(_javascriptVariable, _expectedValue);
}
}

--------------------------------------------------------------------------------------------------------

public class VerifyValueLength extends CubicExBaseTestCase {

private Log log = LogFactory.getLog(VerifyValueLength.class);

/**
* {@inheritDoc}
*/
public void executeTest(final Map<String, String> arguments, final
IElementContext context, final Selenium selenium) throws Exception {

// Retrieve the parameters.
final String _locator = getArgTarget();
final String _valueToCompareTo = getArgValue();

if (log.isInfoEnabled()) {
log.info("VerifyValueLength: target '" + _locator + "', value '" +
_valueToCompareTo + "'.");
}

// Retrieve the field value.
String _valueOfField = selenium.getValue(_locator);
verifyEquals(_valueOfField.length(), _valueToCompareTo);
}

}
--------------------------------------------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages