-
Notifications
You must be signed in to change notification settings - Fork 18
/
ResourceCreationSpec.scala
188 lines (124 loc) · 6.32 KB
/
ResourceCreationSpec.scala
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
/*
* Copyright © 2015-2018 the contributors (see Contributors.md).
*
* This file is part of Knora.
*
* Knora is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Knora is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with Knora. If not, see <http://www.gnu.org/licenses/>.
*/
package org.knora.salsah
import org.openqa.selenium.WebElement
/**
* Tests the SALSAH web interface using Selenium.
*/
class ResourceCreationSpec extends SalsahSpec {
/*
We use the Selenium API directly instead of the ScalaTest wrapper, because the Selenium API is more
powerful and more efficient.
See https://selenium.googlecode.com/git/docs/api/java/index.html?org/openqa/selenium/WebDriver.html
for more documentation.
*/
private val pageUrl = s"http://${settings.hostName}:${settings.httpPort}/index.html"
private val page = new SalsahPage(pageUrl, true)
// How long to wait for results obtained using the 'eventually' function
implicit private val patienceConfig = page.patienceConfig
private val rdfDataObjectsJsonList: String =
"""
[
{"path": "test_data/all_data/incunabula-data.ttl", "name": "http://www.knora.org/data/0803/incunabula"},
{"path": "test_data/demo_data/images-demo-data.ttl", "name": "http://www.knora.org/data/00FF/images"},
{"path": "test_data/all_data/anything-data.ttl", "name": "http://www.knora.org/data/0001/anything"},
{"path": "test_data/all_data/biblio-data.ttl", "name": "http://www.knora.org/data/0802/biblio"}
]
"""
private val anythingUserEmail = "anything.user01@example.org"
private val anythingUserFullName = "Anything User01"
private val imagesUserEmail = "user02.user@example.com"
private val imagesUserFullName = "User02 User"
private val multiUserEmail = "multi.user@example.com"
private val multiUserFullName = "Multi User"
private val testPassword = "test"
private val anythingProjectIri = "http://rdfh.ch/projects/0001"
private val incunabulaProjectIri = "http://rdfh.ch/projects/0803"
// In order to run these tests, start `webapi` using the option `allowReloadOverHTTP`
"The SALSAH home page" should {
"load test data" in {
loadTestData(rdfDataObjectsJsonList)
}
"have the correct title" in {
page.open()
page.getPageTitle should be("System for Annotation and Linkage of Sources in Arts and Humanities")
}
"log in as anything user" in {
page.open()
page.doLogin(email = anythingUserEmail, password = testPassword, fullName = anythingUserFullName)
page.doLogout()
}
// FIXME: Ignored Test!
"create a resource of type images:person" ignore {
page.open()
page.doLogin(email = imagesUserEmail, password = testPassword, fullName = imagesUserFullName)
page.clickAddResourceButton()
val restypes = page.selectRestype("http://www.knora.org/ontology/00FF/images#person")
val label: WebElement = page.getFormFieldByName("__LABEL__")
label.sendKeys("Robin Hood")
val firstname: WebElement = page.getFormFieldByName("http://www.knora.org/ontology/00FF/images#firstname")
firstname.sendKeys("Robin")
val familyname: WebElement = page.getFormFieldByName("http://www.knora.org/ontology/00FF/images#lastname")
familyname.sendKeys("Hood")
val address: WebElement = page.getFormFieldByName("http://www.knora.org/ontology/00FF/images#address")
address.sendKeys("Sherwood Forest")
page.clickSaveButtonForResourceCreationForm()
val window = page.getWindowByID(1)
page.doLogout()
}
// FIXME: Ignored Test!
"create a resource of type anything:thing" ignore {
page.open()
page.doLogin(email = anythingUserEmail, password = testPassword, fullName = anythingUserFullName)
page.clickAddResourceButton()
page.selectVocabulary("0") // select all
page.selectRestype("http://www.knora.org/ontology/0001/anything#Thing")
val resource1Label: WebElement = page.getFormFieldByName("__LABEL__")
try {
resource1Label.sendKeys("Testding")
} catch {
case _: org.openqa.selenium.StaleElementReferenceException =>
val resource1Label: WebElement = page.getFormFieldByName("__LABEL__")
resource1Label.sendKeys("Testding")
}
val resource1FloatVal = page.getFormFieldByName("http://www.knora.org/ontology/0001/anything#hasDecimal")
resource1FloatVal.sendKeys("5.3")
val resource1TextVal = page.getFormFieldByName("http://www.knora.org/ontology/0001/anything#hasText")
resource1TextVal.sendKeys("Dies ist ein Test")
val resource1DateVal = page.getFormFieldByName("http://www.knora.org/ontology/0001/anything#hasDate")
val resource1Monthsel1 = page.getMonthSelection(resource1DateVal, 1)
// choose 15 March 44 BCE
resource1Monthsel1.selectByValue("3")
val resource1Days1 = page.getDays(resource1DateVal, 1)
resource1Days1(15).click()
val resource1Yearsel1 = page.getYearField(resource1DateVal, 1)
resource1Yearsel1.clear()
resource1Yearsel1.sendKeys("44")
val resource1Erasel1 = page.getEraSelection(resource1DateVal, 1)
resource1Erasel1.selectByIndex(1)
page.clickSaveButtonForResourceCreationForm()
val resource1Window = page.getWindowByID(1)
page.closeWindow(resource1Window)
page.doLogout()
}
"close the browser" in {
page.quit()
}
}
}