View Javadoc
1   package net.avcompris.guixer.core;
2   
3   import static com.google.common.base.Preconditions.checkNotNull;
4   
5   import java.io.IOException;
6   
7   import org.openqa.selenium.WebDriver;
8   
9   class MyAbstractUITestCommandImpl implements Command {
10  
11  	private final Context context;
12  
13  	MyAbstractUITestCommandImpl(final Context context) {
14  
15  		this.context = checkNotNull(context, "context");
16  	}
17  
18  	protected WebDriver getDriver() {
19  
20  		throw new IllegalStateException("MyAbstractUITestCommandImpl shoud be subclassed, and getDriver() overriden");
21  	}
22  
23  	protected String getBaseURL() {
24  
25  		throw new IllegalStateException("MyAbstractUITestCommandImpl shoud be subclassed, and getBaseURL() overriden");
26  	}
27  
28  	protected final Command command() throws IOException {
29  
30  		return new CommandConsoleLoggerImpl( //
31  				new CommandDumperLoggerImpl( //
32  						new CommandSeleniumImpl( //
33  								getDriver(), //
34  								getBaseURL(), //
35  								context), //
36  						context), //
37  				context);
38  	}
39  
40  	protected final Command command(final String actionShortDescription) throws IOException {
41  
42  		checkNotNull(actionShortDescription, "actionShortDescription");
43  
44  		return new CommandConsoleLoggerImpl( //
45  				new CommandDumperLoggerImpl( //
46  						new CommandSeleniumImpl( //
47  								getDriver(), //
48  								getBaseURL(), //
49  								context), //
50  						context, //
51  						actionShortDescription), //
52  				context, //
53  				actionShortDescription);
54  	}
55  
56  	@Override
57  	public final Command waitFor(final String locator) throws IOException {
58  
59  		return command().waitFor(locator);
60  	}
61  
62  	@Override
63  	public final Command waitFor(final String locator, final int timeOutSeconds) throws IOException {
64  
65  		return command().waitFor(locator, timeOutSeconds);
66  	}
67  
68  	@Override
69  	public final Command waitForVisible(final String locator) throws IOException {
70  
71  		return command().waitForVisible(locator);
72  	}
73  
74  	@Override
75  	public final Command waitForVisible(final String locator, final int timeOutSeconds) throws IOException {
76  
77  		return command().waitForVisible(locator, timeOutSeconds);
78  	}
79  
80  	@Override
81  	public final Command sleep(final int ms) throws IOException {
82  
83  		return command().sleep(ms);
84  	}
85  
86  	@Override
87  	public final Command takeScreenshot() throws IOException {
88  
89  		return command().takeScreenshot();
90  	}
91  
92  	@Override
93  	public final Command takeScreenshot(final String label) throws IOException {
94  
95  		return command().takeScreenshot(label);
96  	}
97  
98  	@Override
99  	public Command get() throws IOException {
100 
101 		return command().get();
102 	}
103 
104 	@Override
105 	public SwitchTo switchTo() throws IOException {
106 
107 		return command().switchTo();
108 	}
109 
110 	@Override
111 	public Command log(final String text) throws IOException {
112 
113 		return command().log(text);
114 	}
115 
116 	@Override
117 	public Command clear(final String locator) throws IOException {
118 
119 		return command().clear(locator);
120 	}
121 
122 	@Override
123 	public Command click(final String locator) throws IOException {
124 
125 		return command().click(locator);
126 	}
127 
128 	@Override
129 	public Command submit(final String locator) throws IOException {
130 
131 		return command().submit(locator);
132 	}
133 
134 	@Override
135 	public Command select(final String locator, final int value) throws IOException {
136 
137 		return command().select(locator, value);
138 	}
139 
140 	@Override
141 	public Command select(final String locator, final String value) throws IOException {
142 
143 		return command().select(locator, value);
144 	}
145 
146 	@Override
147 	public Command assertHasClass(final String locator, final String className) throws IOException {
148 
149 		return command().assertHasClass(locator, className);
150 	}
151 
152 	@Override
153 	public Command assertDoesntHaveClass(final String locator, final String className) throws IOException {
154 
155 		return command().assertDoesntHaveClass(locator, className);
156 	}
157 
158 	@Override
159 	public Command sendKeys(final String locator, final CharSequence... keys) throws IOException {
160 
161 		return command().sendKeys(locator, keys);
162 	}
163 
164 	@Override
165 	public Command sendKeysSecret(final String locator, final String secret) throws IOException {
166 
167 		return command().sendKeysSecret(locator, secret);
168 	}
169 
170 	@Override
171 	public Command skip() throws IOException {
172 
173 		return command().skip();
174 	}
175 
176 	@Override
177 	public Command when(final String label, final boolean condition) throws IOException {
178 
179 		return command().when(label, condition);
180 	}
181 
182 	@Override
183 	public Command when(final boolean condition) throws IOException {
184 
185 		return command().when(condition);
186 	}
187 }