-
Notifications
You must be signed in to change notification settings - Fork 23
/
PageHelper.java
122 lines (109 loc) · 5.22 KB
/
PageHelper.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
/*
* #%L
* NetarchiveSuite System test
* %%
* Copyright (C) 2005 - 2018 The Royal Danish Library,
* the National Library of France and the Austrian National Library.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program 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 General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package dk.netarkivet.systemtest.page;
import java.util.HashMap;
import java.util.Map;
import org.jaccept.TestEventManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class PageHelper {
private static WebDriver driver;
private static String baseUrl;
private static Map<MenuPages, String> pageMapping = new HashMap<MenuPages, String>();
public static enum MenuPages {
Frontpage, SelectiveHarvests, SnapshotHarvests, Schedules, FindDomains, CreateDomain, DomainStatistics, AliasSummary, EditHarvestTemplates, GlobalCrawlerTraps, ExtendedFields, AllJobs, AllJobsPerDomain, RunningJobs, Filestatus, BatchjobOverview, ViewerproxyStatus, OverviewOfTheSystemState
}
static {
pageMapping.put(MenuPages.Frontpage, "HarvestDefinition");
pageMapping.put(MenuPages.SelectiveHarvests, "HarvestDefinition/Definitions-selective-harvests.jsp");
pageMapping.put(MenuPages.SnapshotHarvests, "HarvestDefinition/Definitions-snapshot-harvests.jsp");
pageMapping.put(MenuPages.Schedules, "HarvestDefinition/Definitions-schedules.jsp");
pageMapping.put(MenuPages.FindDomains, "HarvestDefinition/Definitions-find-domains.jsp");
pageMapping.put(MenuPages.CreateDomain, "HarvestDefinition/Definitions-create-domain.jsp");
pageMapping.put(MenuPages.DomainStatistics, "HarvestDefinition/Definitions-domain-statistics.jsp");
pageMapping.put(MenuPages.AliasSummary, "HarvestDefinition/Definitions-alias-summary.jsp");
pageMapping.put(MenuPages.EditHarvestTemplates, "HarvestDefinition/Definitions-edit-harvest-templates.jsp");
pageMapping.put(MenuPages.GlobalCrawlerTraps, "HarvestDefinition/Definitions-edit-global-crawler-traps.jsp");
pageMapping.put(MenuPages.ExtendedFields, "HarvestDefinition/Definitions-list-extendedfields.jsp");
pageMapping.put(MenuPages.AllJobs, "History/Harveststatus-alljobs.jsp");
pageMapping.put(MenuPages.AllJobsPerDomain, "History/Harveststatus-perdomain.jsp");
pageMapping.put(MenuPages.RunningJobs, "History/Harveststatus-running.jsp");
pageMapping.put(MenuPages.Filestatus, "HarvestDefinition/Definitions-selective-harvests.jsp");
pageMapping.put(MenuPages.BatchjobOverview, "BitPreservation/Bitpreservation-filestatus.jsp");
pageMapping.put(MenuPages.ViewerproxyStatus, "QA/QA-status.jsp");
pageMapping.put(MenuPages.OverviewOfTheSystemState, "Status/Monitor-JMXsummary.jsp");
}
public static void gotoPage(MenuPages page) {
checkInitialization();
String pageUrl = pageMapping.get(page);
TestEventManager.getInstance().addStimuli("Loading " + pageUrl);
driver.get(baseUrl + "/" + pageUrl);
}
/**
* Load the page relative to the base ur.
*
* @param subURL
*/
public static void gotoSubPage(String subURL) {
checkInitialization();
TestEventManager.getInstance().addStimuli("Loading " + subURL);
driver.get(baseUrl + "/" + subURL);
}
/**
* Load the page relative to the base url. Doesn't log the page reload
*
* @param subURL
*/
public static void reloadSubPage(String subURL) {
checkInitialization();
System.out.println("Loading subpage " + subURL);
driver.get(baseUrl + "/" + subURL);
System.out.println("Loaded subpage " + subURL);
}
public static void clickLink(String linkText) {
checkInitialization();
TestEventManager.getInstance().addStimuli("Clicking '" + linkText + "' link.");
driver.findElement(By.partialLinkText(linkText)).click();
}
public static void initialize(WebDriver theDriver, String theBaseUrl) {
driver = theDriver;
baseUrl = theBaseUrl;
checkInitialization();
}
public static WebDriver getWebDriver() {
checkInitialization();
return driver;
}
/**
* In case of button clicks causing page loads this function should be called to ensure the new page is finished
* loading before the test is continued.
*/
public static void waitForPageToLoad() {
driver.findElement(By.className("systeminfo"));
}
private static void checkInitialization() {
if (driver == null || baseUrl == null) {
throw new IllegalStateException("Failed to goto page, webdriver " + "and baseurl hasn't been set.");
}
}
}