01: // Copyright © 2002-2005 Canoo Engineering AG, Switzerland.
02: package com.canoo.webtest.steps.verify;
03:
04: import com.canoo.webtest.engine.StepFailedException;
05: import com.canoo.webtest.self.TestBlock;
06: import com.canoo.webtest.self.ThrowAssert;
07: import com.canoo.webtest.steps.BaseStepTestCase;
08: import com.canoo.webtest.steps.Step;
09:
10: public class VerifyElementTest extends BaseStepTestCase {
11:
12: protected Step createStep() {
13: return new VerifyElement();
14: }
15:
16: public void testExcecutionFailureScenarios() {
17: final VerifyElement plainStep = (VerifyElement) getStep();
18: assertStepRejectsNullParam("text", new TestBlock() {
19: public void call() throws Exception {
20: executeStep(plainStep);
21: }
22: });
23: plainStep.setText("text");
24: assertStepRejectsNullParam("type", new TestBlock() {
25: public void call() throws Exception {
26: executeStep(plainStep);
27: }
28: });
29: plainStep.setType("type");
30: String message = ThrowAssert.assertThrows(
31: StepFailedException.class, new TestBlock() {
32: public void call() throws Exception {
33: executeStep(plainStep);
34: }
35: });
36: assertTrue("no element yet", message
37: .startsWith("No element of type"));
38:
39: final VerifyElement tooManyStep = new VerifyElement() {
40: protected int getNumberOfHits() {
41: return 2;
42: }
43: };
44:
45: tooManyStep.setText("text");
46: tooManyStep.setType("type");
47: message = ThrowAssert.assertThrows(StepFailedException.class,
48: new TestBlock() {
49: public void call() throws Exception {
50: executeStep(tooManyStep);
51: }
52: });
53: assertTrue("too many hits", message
54: .startsWith("More than 1 element"));
55: }
56: }
|