Skip to content

Commit 2453371

Browse files
committed
test: implement tests for driver options
1 parent c861159 commit 2453371

File tree

4 files changed

+263
-0
lines changed

4 files changed

+263
-0
lines changed
Binary file not shown.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.android;
18+
19+
import io.appium.java_client.remote.AutomationName;
20+
import io.appium.java_client.remote.MobilePlatform;
21+
import org.junit.Test;
22+
import org.openqa.selenium.MutableCapabilities;
23+
import org.openqa.selenium.ScreenOrientation;
24+
25+
import java.net.MalformedURLException;
26+
import java.net.URL;
27+
import java.time.Duration;
28+
29+
import static org.junit.Assert.assertEquals;
30+
31+
public class AndroidOptionsTest {
32+
private AndroidMobileOptions androidMobileOptions = new AndroidMobileOptions();
33+
34+
@Test
35+
public void setsPlatformNameByDefault() {
36+
assertEquals(MobilePlatform.ANDROID, androidMobileOptions.getPlatformName());
37+
}
38+
39+
@Test
40+
public void acceptsExistingCapabilities() {
41+
MutableCapabilities capabilities = new MutableCapabilities();
42+
capabilities.setCapability("deviceName", "Pixel");
43+
capabilities.setCapability("platformVersion", "10");
44+
capabilities.setCapability("newCommandTimeout", 60);
45+
46+
androidMobileOptions = new AndroidMobileOptions(capabilities);
47+
48+
assertEquals("Pixel", androidMobileOptions.getDeviceName());
49+
assertEquals("10", androidMobileOptions.getPlatformVersion());
50+
assertEquals(Duration.ofSeconds(60), androidMobileOptions.getNewCommandTimeout());
51+
}
52+
53+
@Test
54+
public void acceptsMobileCapabilities() throws MalformedURLException {
55+
androidMobileOptions.setApp(new URL("http://example.com/myapp.apk"))
56+
.setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2)
57+
.setPlatformVersion("10")
58+
.setDeviceName("Pixel")
59+
.setOtherApps("/path/to/app.apk")
60+
.setLocale("fr_CA")
61+
.setUdid("1ae203187fc012g")
62+
.setOrientation(ScreenOrientation.LANDSCAPE)
63+
.setNewCommandTimeout(Duration.ofSeconds(60))
64+
.setLanguage("fr");
65+
66+
assertEquals("http://example.com/myapp.apk", androidMobileOptions.getApp());
67+
assertEquals(AutomationName.ANDROID_UIAUTOMATOR2, androidMobileOptions.getAutomationName());
68+
assertEquals("10", androidMobileOptions.getPlatformVersion());
69+
assertEquals("Pixel", androidMobileOptions.getDeviceName());
70+
assertEquals("/path/to/app.apk", androidMobileOptions.getOtherApps());
71+
assertEquals("fr_CA", androidMobileOptions.getLocale());
72+
assertEquals("1ae203187fc012g", androidMobileOptions.getUdid());
73+
assertEquals(ScreenOrientation.LANDSCAPE, androidMobileOptions.getOrientation());
74+
assertEquals(Duration.ofSeconds(60), androidMobileOptions.getNewCommandTimeout());
75+
assertEquals("fr", androidMobileOptions.getLanguage());
76+
}
77+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.ios;
18+
19+
import io.appium.java_client.remote.AutomationName;
20+
import io.appium.java_client.remote.MobilePlatform;
21+
import org.junit.Test;
22+
import org.openqa.selenium.MutableCapabilities;
23+
import org.openqa.selenium.ScreenOrientation;
24+
25+
import java.net.MalformedURLException;
26+
import java.net.URL;
27+
import java.time.Duration;
28+
29+
import static org.junit.Assert.assertEquals;
30+
31+
public class IOSOptionsTest {
32+
private IOSMobileOptions iosMobileOptions = new IOSMobileOptions();
33+
34+
@Test
35+
public void setsPlatformNameByDefault() {
36+
assertEquals(MobilePlatform.IOS, iosMobileOptions.getPlatformName());
37+
}
38+
39+
@Test
40+
public void acceptsExistingCapabilities() {
41+
MutableCapabilities capabilities = new MutableCapabilities();
42+
capabilities.setCapability("deviceName", "Pixel");
43+
capabilities.setCapability("platformVersion", "10");
44+
capabilities.setCapability("newCommandTimeout", 60);
45+
46+
iosMobileOptions = new IOSMobileOptions(capabilities);
47+
48+
assertEquals("Pixel", iosMobileOptions.getDeviceName());
49+
assertEquals("10", iosMobileOptions.getPlatformVersion());
50+
assertEquals(Duration.ofSeconds(60), iosMobileOptions.getNewCommandTimeout());
51+
}
52+
53+
@Test
54+
public void acceptsMobileCapabilities() throws MalformedURLException {
55+
iosMobileOptions.setApp(new URL("http://example.com/myapp.apk"))
56+
.setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2)
57+
.setPlatformVersion("10")
58+
.setDeviceName("Pixel")
59+
.setOtherApps("/path/to/app.apk")
60+
.setLocale("fr_CA")
61+
.setUdid("1ae203187fc012g")
62+
.setOrientation(ScreenOrientation.LANDSCAPE)
63+
.setNewCommandTimeout(Duration.ofSeconds(60))
64+
.setLanguage("fr");
65+
66+
assertEquals("http://example.com/myapp.apk", iosMobileOptions.getApp());
67+
assertEquals(AutomationName.ANDROID_UIAUTOMATOR2, iosMobileOptions.getAutomationName());
68+
assertEquals("10", iosMobileOptions.getPlatformVersion());
69+
assertEquals("Pixel", iosMobileOptions.getDeviceName());
70+
assertEquals("/path/to/app.apk", iosMobileOptions.getOtherApps());
71+
assertEquals("fr_CA", iosMobileOptions.getLocale());
72+
assertEquals("1ae203187fc012g", iosMobileOptions.getUdid());
73+
assertEquals(ScreenOrientation.LANDSCAPE, iosMobileOptions.getOrientation());
74+
assertEquals(Duration.ofSeconds(60), iosMobileOptions.getNewCommandTimeout());
75+
assertEquals("fr", iosMobileOptions.getLanguage());
76+
}
77+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.remote;
18+
19+
import org.junit.Test;
20+
import org.openqa.selenium.MutableCapabilities;
21+
import org.openqa.selenium.ScreenOrientation;
22+
23+
import java.net.MalformedURLException;
24+
import java.net.URL;
25+
import java.time.Duration;
26+
import java.util.ArrayList;
27+
28+
import static org.junit.Assert.*;
29+
30+
public class MobileOptionsTest {
31+
private MobileOptions mobileOptions = new MobileOptions<>();
32+
33+
@Test
34+
public void acceptsExistingCapabilities() {
35+
MutableCapabilities capabilities = new MutableCapabilities();
36+
capabilities.setCapability("deviceName", "Pixel");
37+
capabilities.setCapability("platformVersion", "10");
38+
capabilities.setCapability("newCommandTimeout", 60);
39+
40+
mobileOptions = new MobileOptions<>(capabilities);
41+
42+
assertEquals("Pixel", mobileOptions.getDeviceName());
43+
assertEquals("10", mobileOptions.getPlatformVersion());
44+
assertEquals(Duration.ofSeconds(60), mobileOptions.getNewCommandTimeout());
45+
}
46+
47+
@Test
48+
public void acceptsMobileCapabilities() throws MalformedURLException {
49+
mobileOptions.setApp(new URL("http://example.com/myapp.apk"))
50+
.setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2)
51+
.setPlatformVersion("10")
52+
.setDeviceName("Pixel")
53+
.setOtherApps("/path/to/app.apk")
54+
.setLocale("fr_CA")
55+
.setUdid("1ae203187fc012g")
56+
.setOrientation(ScreenOrientation.LANDSCAPE)
57+
.setNewCommandTimeout(Duration.ofSeconds(60))
58+
.setLanguage("fr");
59+
60+
assertEquals("http://example.com/myapp.apk", mobileOptions.getApp());
61+
assertEquals(AutomationName.ANDROID_UIAUTOMATOR2, mobileOptions.getAutomationName());
62+
assertEquals("10", mobileOptions.getPlatformVersion());
63+
assertEquals("Pixel", mobileOptions.getDeviceName());
64+
assertEquals("/path/to/app.apk", mobileOptions.getOtherApps());
65+
assertEquals("fr_CA", mobileOptions.getLocale());
66+
assertEquals("1ae203187fc012g", mobileOptions.getUdid());
67+
assertEquals(ScreenOrientation.LANDSCAPE, mobileOptions.getOrientation());
68+
assertEquals(Duration.ofSeconds(60), mobileOptions.getNewCommandTimeout());
69+
assertEquals("fr", mobileOptions.getLanguage());
70+
}
71+
72+
@Test
73+
public void acceptsMobileBooleanCapabilityDefaults() {
74+
mobileOptions.setClearSystemFiles()
75+
.setAutoWebview()
76+
.setEnablePerformanceLogging()
77+
.setEventTimings()
78+
.setAutoWebview()
79+
.setFullReset()
80+
.setPrintPageSourceOnFindFailure();
81+
82+
assertTrue(mobileOptions.doesClearSystemFiles());
83+
assertTrue(mobileOptions.doesAutoWebview());
84+
assertTrue(mobileOptions.isEnablePerformanceLogging());
85+
assertTrue(mobileOptions.doesEventTimings());
86+
assertTrue(mobileOptions.doesAutoWebview());
87+
assertTrue(mobileOptions.doesFullReset());
88+
assertTrue(mobileOptions.doesPrintPageSourceOnFindFailure());
89+
}
90+
91+
@Test
92+
public void setsMobileBooleanCapabilities() {
93+
mobileOptions.setClearSystemFiles(false)
94+
.setAutoWebview(false)
95+
.setEnablePerformanceLogging(false)
96+
.setEventTimings(false)
97+
.setAutoWebview(false)
98+
.setFullReset(false)
99+
.setPrintPageSourceOnFindFailure(false);
100+
101+
assertFalse(mobileOptions.doesClearSystemFiles());
102+
assertFalse(mobileOptions.doesAutoWebview());
103+
assertFalse(mobileOptions.isEnablePerformanceLogging());
104+
assertFalse(mobileOptions.doesEventTimings());
105+
assertFalse(mobileOptions.doesAutoWebview());
106+
assertFalse(mobileOptions.doesFullReset());
107+
assertFalse(mobileOptions.doesPrintPageSourceOnFindFailure());
108+
}
109+
}

0 commit comments

Comments
 (0)