/
WebTestOrderFormIT.java
203 lines (183 loc) · 7.2 KB
/
WebTestOrderFormIT.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package ch.ivyteam.integrationtest;
import static com.codeborne.selenide.CollectionCondition.size;
import static com.codeborne.selenide.CollectionCondition.sizeGreaterThanOrEqual;
import static com.codeborne.selenide.CollectionCondition.sizeLessThanOrEqual;
import static com.codeborne.selenide.CollectionCondition.texts;
import static com.codeborne.selenide.Condition.and;
import static com.codeborne.selenide.Condition.exactText;
import static com.codeborne.selenide.Condition.exactValue;
import static com.codeborne.selenide.Condition.exist;
import static com.codeborne.selenide.Condition.hidden;
import static com.codeborne.selenide.Condition.not;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Condition.value;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;
import static com.codeborne.selenide.Selenide.$$x;
import static com.codeborne.selenide.Selenide.$x;
import static com.codeborne.selenide.Selenide.open;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import com.axonivy.ivy.webtest.IvyWebTest;
import com.axonivy.ivy.webtest.engine.EngineUrl;
import com.axonivy.ivy.webtest.primeui.PrimeUi;
import com.axonivy.ivy.webtest.primeui.widget.InputNumber;
import com.axonivy.ivy.webtest.primeui.widget.SelectOneMenu;
import com.codeborne.selenide.CollectionCondition;
import com.codeborne.selenide.Condition;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
@IvyWebTest
public class WebTestOrderFormIT
{
@BeforeEach
void startProcess()
{
//Start your engine and copy the process start link.
//You can use the EngineUrl Util to start the order process:
open(EngineUrl.createProcessUrl("/crm/1700F6B9A99952AD/orderProduct.ivp"));
}
@Test
void testPriceUpdateAfterProductChanges()
{
//Use Testutil for PrimeFaces SelectOneMenu provided by the primeui-tester
SelectOneMenu product = PrimeUi.selectOne(By.id("form:product"));
//Check price for table
product.selectItemByLabel("Table");
$(By.id("form:price")).shouldBe(exactText("375.5"));
//Select chair and check price has changed
product.selectItemByLabel("Chair");
$(By.id("form:price")).shouldBe(exactText("89.6"));
}
@Test
void testAmountInputCanOnlyBeNumbersTo100()
{
//Test init value of amount
InputNumber inputNumber = PrimeUi.inputNumber(By.id("form:amount"));
inputNumber.should(exactValue("1"));
//Test that only numbers to 100 can be placed into the amount input
inputNumber.setValue("100");
inputNumber.should(exactValue("100"));
inputNumber.setValue("101");
inputNumber.should(exactValue("10"));
}
@Test
void testProductCanBeAdded()
{
orderIsEmpty();
addProductToOrder("Table", 1);
orderContains("Table");
}
@Test
void testMultipleProductsCanBeAdded()
{
orderIsEmpty();
addProductToOrder("Table", 1);
addProductToOrder("Chair", 1);
orderContains("Table");
orderContains("Chair");
}
@Test
void testPriceIsMultipliedByAmount()
{
addProductToOrder("Chair", 4);
String expectedPrice = String.valueOf(4 * 89.6);
orderContains("Chair");
orderContains("4");
orderContains(expectedPrice);
}
/**
* Show how the different selectors can be used.
* Be aware that if you use the css selector with JSF you need to write "\\:" instead of ":".
* @see Selenide#$(String)
* @see Selenide#$(String, int)
* @see Selenide#$(By)
* @see Selenide#$(By, int)
* @see Selenide#$$(String)
* @see Selenide#$$(By)
*/
@Test
void showSelectorPossibilities()
{
addProductToOrder("Table", 1);
addProductToOrder("Table", 1);
addProductToOrder("Table", 1);
addProductToOrder("Chair", 1);
addProductToOrder("Chair", 1);
//single element with css selector
$("#form").shouldBe(visible); //by id
$("form").shouldBe(visible); //by tag
$(".ui-datatable").shouldBe(visible); //by class
$x("//form").shouldBe(visible); //by xpath
//single element with By selector
$(By.id("form")).shouldBe(visible);
$(By.tagName("form")).shouldBe(visible);
$(By.className("ui-datatable")).shouldBe(visible);
$(By.xpath("//form")).shouldBe(visible);
//nth element of multiple
$("label", 2).shouldHave(text("Amount"));
$(By.tagName("label"), 3).shouldHave(text("Single Price"));
//all elements with css selector
$$("label").shouldHave(size(4)); //by tag
$$(".ui-outputlabel").shouldHave(size(3)); //by class
$$x("//label").shouldHave(size(4)); //by xpath
//all elements with By selector
$$(By.tagName("label")).shouldHave(size(4));
$$(By.className("ui-outputlabel")).shouldHave(size(3));
$$(By.xpath("//label")).shouldHave(size(4));
//complex css selectors
//single element css class inside id
$("#form\\:amount .ui-inputfield").shouldHave(value("1"));
$(By.id("form:amount")).find(By.className("ui-inputfield")).shouldHave(value("1"));
//all labels inside id
$$("#form\\:orderTable tbody tr").shouldHave(size(5));
$(By.id("form:orderTable")).find(By.tagName("tbody")).findAll(By.tagName("tr")).shouldHave(size(5));
//all table rows which contains "Table"
$$("tbody tr").filter(text("Table")).shouldHave(sizeGreaterThanOrEqual(3));
$(By.tagName("tbody")).findAll("tr").filter(text("Chair")).shouldHave(sizeLessThanOrEqual(2));
}
/**
* show possible assertions/conditions which can be tested.
* @see SelenideElement#should(Condition...)
* @see ElementsCollection#shouldBe(CollectionCondition...)
*/
@Test
void showAssertionPossibilities()
{
//assertions can have multiple conditions or they can be stacked
$(By.id("form:addProduct")).shouldBe(visible, exist);
$(By.id("form:addProduct")).shouldBe(visible).should(exist);
//you can create conditions for your need
Condition clickable = and("should be clickable", visible, exist);
$(By.id("form:addProduct")).shouldBe(clickable);
//they can be inverted
$(By.id("notExistingElement")).shouldNotBe(exist);
$(By.id("notExistingElement")).shouldBe(not(exist));
//they can exist but are hidden
$(By.id("form:product_input")).should(exist, not(visible));
$(By.id("form:product_input")).shouldBe(hidden);
//conditions on multiple elements
$$(By.className("ui-outputlabel")).shouldBe(texts("Product", "Amount", "Single Price"));
}
private void addProductToOrder(String product, int amount)
{
//Use Testutil for PrimeFaces SelectOneMenu provided by the primeui-tester
PrimeUi.selectOne(By.id("form:product")).selectItemByLabel(product);
//Set amount
PrimeUi.inputNumber(By.id("form:amount")).setValue(String.valueOf(amount));
//Add product to order
$(By.id("form:addProduct")).click();
}
private void orderIsEmpty()
{
orderContains("No records found.");
}
private void orderContains(String contains)
{
//Use Testutil for PrimeFaces DataTable provided by the primeui-tester
PrimeUi.table(By.id("form:orderTable")).contains(contains);
}
}