/
RacePage.java
73 lines (51 loc) · 1.86 KB
/
RacePage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.escanan.ealden.race.page;
import com.escanan.ealden.race.model.Racer;
import com.escanan.ealden.race.model.SpeedType;
import org.openqa.selenium.By;
import static java.lang.Integer.parseInt;
public class RacePage extends BasePage {
private static final String ROOT_URL = "http://localhost:8080/";
private final By testRoll = By.id("test-roll");
private final By raceControls = By.id("race-controls");
private final By raceOver = By.id("race-over");
private final By normalSpeed = By.id("roll-normal-speed");
private final By superSpeed = By.id("roll-super-speed");
private final By newRace = By.id("new-race");
private final By message = By.id("message");
public RacePage(boolean headless) {
super(headless);
}
public RacePage load() {
navigateTo(ROOT_URL);
return this;
}
public RacePage roll(int roll, SpeedType speedType) {
input(testRoll, roll);
if (SpeedType.NORMAL == speedType) {
click(normalSpeed);
} else if (SpeedType.SUPER == speedType) {
click(superSpeed);
}
waitUntilProcessingComplete();
return this;
}
public RacePage newRace() {
click(newRace);
waitUntilProcessingComplete();
return this;
}
public int getPositionOf(Racer racer) {
return parseInt(findTestElement(racer.getId(), "position").getText());
}
public int getDamageOf(Racer racer) {
return parseInt(findTestElement(racer.getId(), "damage").getText());
}
public boolean isOver() {
boolean raceControlsHidden = findElements(raceControls).isEmpty();
boolean raceOverHidden = findElements(raceOver).isEmpty();
return (raceControlsHidden && !raceOverHidden);
}
public String getMessage() {
return findElement(message).getText().trim();
}
}