Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/java/test/org/openqa/selenium/PlatformTest.java
1865 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
package org.openqa.selenium;
19
20
import static org.assertj.core.api.Assertions.assertThat;
21
import static org.openqa.selenium.Platform.ANDROID;
22
import static org.openqa.selenium.Platform.ANY;
23
import static org.openqa.selenium.Platform.CATALINA;
24
import static org.openqa.selenium.Platform.IOS;
25
import static org.openqa.selenium.Platform.LINUX;
26
import static org.openqa.selenium.Platform.MAC;
27
import static org.openqa.selenium.Platform.SEQUOIA;
28
import static org.openqa.selenium.Platform.UNIX;
29
import static org.openqa.selenium.Platform.VISTA;
30
import static org.openqa.selenium.Platform.WIN11;
31
import static org.openqa.selenium.Platform.WIN8;
32
import static org.openqa.selenium.Platform.WIN8_1;
33
import static org.openqa.selenium.Platform.WINDOWS;
34
import static org.openqa.selenium.Platform.XP;
35
36
import org.junit.jupiter.api.Tag;
37
import org.junit.jupiter.api.Test;
38
39
@Tag("UnitTests")
40
class PlatformTest {
41
42
@Test
43
void testXpIsWindows() {
44
assertThat(XP.is(WINDOWS)).isTrue();
45
}
46
47
@Test
48
void testVistaIsWindows() {
49
assertThat(VISTA.is(WINDOWS)).isTrue();
50
}
51
52
@Test
53
void testWin8IsWindows() {
54
assertThat(WIN8.is(WINDOWS)).isTrue();
55
}
56
57
@Test
58
void testWin81IsWindows() {
59
assertThat(WIN8_1.is(WINDOWS)).isTrue();
60
}
61
62
@Test
63
void testWindows11IsWindows() {
64
assertThat(WIN11.is(WINDOWS)).isTrue();
65
}
66
67
@Test
68
void testLinuxIsUnix() {
69
assertThat(LINUX.is(UNIX)).isTrue();
70
}
71
72
@Test
73
void testUnixIsNotLinux() {
74
assertThat(UNIX.is(LINUX)).isFalse();
75
}
76
77
@Test
78
void testXpIsAny() {
79
assertThat(XP.is(ANY)).isTrue();
80
}
81
82
@Test
83
void testWindowsIsAny() {
84
assertThat(WINDOWS.is(ANY)).isTrue();
85
}
86
87
@Test
88
void testLinuxIsAny() {
89
assertThat(LINUX.is(ANY)).isTrue();
90
}
91
92
@Test
93
void windowsIsNotMacOS() {
94
// Both of these are platform definitions, so return "null" for the family.
95
assertThat(WINDOWS.is(MAC)).isFalse();
96
}
97
98
@Test
99
void testUnixIsAny() {
100
assertThat(UNIX.is(ANY)).isTrue();
101
}
102
103
@Test
104
void testShouldIdentifyXPVariants() {
105
assertAllAre(Platform.WINDOWS, "Windows 2003", "xp", "windows", "winnt");
106
}
107
108
@Test
109
void testShouldIdentifyVistaVariants() {
110
assertAllAre(Platform.VISTA, "Windows Vista", "windows server 2008");
111
}
112
113
@Test
114
void testShouldIdentifyMacVariants() {
115
assertAllAre(Platform.MAC, "Darwin", "Mac OS X");
116
}
117
118
@Test
119
void testShouldIdentifyUnixVariants() {
120
assertAllAre(Platform.UNIX, "solaris", "bsd");
121
}
122
123
@Test
124
void testShouldIdentifyLinux() {
125
assertAllAre(Platform.LINUX, "Linux");
126
}
127
128
@Test
129
void windowsIsWindows() {
130
assertThat(WINDOWS.is(WINDOWS)).isTrue();
131
}
132
133
@Test
134
void macIsMac() {
135
assertThat(MAC.is(MAC)).isTrue();
136
}
137
138
@Test
139
void linuxIsLinux() {
140
assertThat(LINUX.is(LINUX)).isTrue();
141
}
142
143
@Test
144
void unixIsUnix() {
145
assertThat(UNIX.is(UNIX)).isTrue();
146
}
147
148
@Test
149
void androidIAndroid() {
150
assertThat(ANDROID.is(ANDROID)).isTrue();
151
}
152
153
@Test
154
void iosIsIos() {
155
assertThat(IOS.is(IOS)).isTrue();
156
}
157
158
@Test
159
void testWindows8Detection() {
160
assertThat(Platform.extractFromSysProperty("windows nt (unknown)", "6.2"))
161
.isEqualTo(Platform.WIN8);
162
}
163
164
@Test
165
void testWindows81Detection() {
166
assertThat(Platform.extractFromSysProperty("windows nt (unknown)", "6.3"))
167
.isEqualTo(Platform.WIN8_1);
168
}
169
170
@Test
171
void testWindowsIsWindows() {
172
assertThat(WINDOWS).isEqualTo(Platform.fromString("windows"));
173
}
174
175
@Test
176
void testWindowsIsNotEmpty() {
177
assertThat(WINDOWS).isNotEqualTo(Platform.fromString(""));
178
}
179
180
@Test
181
void canParseMacOsXCorrectly() {
182
assertThat(Platform.fromString("Mac OS X")).isEqualTo(MAC);
183
}
184
185
@Test
186
void testAnyIsFromStringEmpty() {
187
assertThat(ANY).isEqualTo(Platform.fromString(""));
188
}
189
190
@Test
191
void testAnyIsFromStringAny() {
192
assertThat(ANY).isEqualTo(Platform.fromString("any"));
193
}
194
195
@Test
196
void testAnyIsNotFromStringWindows() {
197
assertThat(ANY).isNotEqualTo(Platform.fromString("windows"));
198
}
199
200
@Test
201
void catalinaIsMac() {
202
assertThat(CATALINA.is(MAC)).isTrue();
203
}
204
205
@Test
206
void sequoiaIsMac() {
207
assertThat(SEQUOIA.is(MAC)).isTrue();
208
}
209
210
@Test
211
void canParseCatalinaFromOSName() {
212
assertThat(Platform.fromString("macOS 10.15")).isEqualTo(CATALINA);
213
}
214
215
private void assertAllAre(Platform platform, String... osNames) {
216
for (String osName : osNames) {
217
Platform seen = Platform.extractFromSysProperty(osName);
218
assertThat(seen.is(platform)).isTrue();
219
}
220
}
221
}
222
223