/
PageSpecReaderV2Test.java
80 lines (66 loc) · 3.43 KB
/
PageSpecReaderV2Test.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
/*******************************************************************************
* Copyright 2015 Ivan Shubin http://mindengine.net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package net.mindengine.galen.tests.speclang2.pagespec;
import net.mindengine.galen.browser.Browser;
import net.mindengine.galen.browser.SeleniumBrowser;
import net.mindengine.galen.components.mocks.driver.MockedDriver;
import net.mindengine.galen.speclang2.reader.pagespec.PageSpecReaderV2;
import net.mindengine.galen.specs.page.CorrectionsRect;
import net.mindengine.galen.specs.page.Locator;
import net.mindengine.galen.specs.reader.page.PageSpec;
import org.testng.annotations.Test;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
public class PageSpecReaderV2Test {
private static final Browser NO_BROWSER = null;
@Test
public void shouldRead_objectDefinitions() throws IOException {
PageSpec pageSpec = readPageSpec("speclang2/object-definitions.gspec");
assertThat(pageSpec.getObjects(), is((Map<String, Locator>)new HashMap<String, Locator>(){{
put("header", new Locator("css", "#header"));
put("header-icon", new Locator("css", "#header img"));
put("button", new Locator("xpath", "//div[@id='button']"));
put("cancel-link", new Locator("id", "cancel"));
put("caption", new Locator("css", "#wrapper")
.withCorrections(new CorrectionsRect(
new CorrectionsRect.Correction(0, CorrectionsRect.Type.PLUS),
new CorrectionsRect.Correction(100, CorrectionsRect.Type.PLUS),
new CorrectionsRect.Correction(5, CorrectionsRect.Type.MINUS),
new CorrectionsRect.Correction(7, CorrectionsRect.Type.PLUS)
)));
}}));
}
@Test
public void shouldRead_objectDefinitions_withMultiObjects() throws IOException {
PageSpec pageSpec = readPageSpec("speclang2/object-definitions-multi-objects.gspec",
new SeleniumBrowser(new MockedDriver("/speclang2/mocks/menu-items.json")));
assertThat(pageSpec.getObjects(), is((Map<String, Locator>)new HashMap<String, Locator>(){{
put("menu-item-1", new Locator("css", "#menu li", 1));
put("menu-item-2", new Locator("css", "#menu li", 2));
put("menu-item-3", new Locator("css", "#menu li", 3));
put("menu-item-4", new Locator("css", "#menu li", 4));
}}));
}
private PageSpec readPageSpec(String resource) throws IOException {
return readPageSpec(resource, NO_BROWSER);
}
private PageSpec readPageSpec(String resource, Browser browser) throws IOException {
return new PageSpecReaderV2().read(resource, browser);
}
}