Skip to content

Commit 568eeed

Browse files
feat: Add wrappers for the Windows screen recorder (#1313)
1 parent 6cd31e2 commit 568eeed

14 files changed

+331
-92
lines changed

azure-pipelines.yml

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,46 @@ variables:
1515
IOS_PLATFORM_VERSION: 12.2
1616
IOS_DEVICE_NAME: iPhone X
1717

18-
steps:
19-
- task: NodeTool@0
20-
inputs:
21-
versionSpec: '11.x'
22-
23-
- script: |
24-
echo "Configuring Environment"
25-
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;$(ANDROID_EMU_TARGET);$(ANDROID_EMU_TAG);$(ANDROID_EMU_ABI)'
26-
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n "$(ANDROID_EMU_NAME)" -k 'system-images;$(ANDROID_EMU_TARGET);$(ANDROID_EMU_TAG);$(ANDROID_EMU_ABI)' --force
27-
echo $ANDROID_HOME/emulator/emulator -list-avds
28-
29-
echo "Starting emulator"
30-
nohup $ANDROID_HOME/emulator/emulator -avd "$(ANDROID_EMU_NAME)" -no-snapshot > /dev/null 2>&1 &
31-
$ANDROID_HOME/platform-tools/adb wait-for-device
32-
while [[ $? -ne 0 ]]; do sleep 1; $ANDROID_HOME/platform-tools/adb shell pm list packages; done;
33-
$ANDROID_HOME/platform-tools/adb devices
34-
echo "Emulator started"
35-
36-
sudo xcode-select -s /Applications/Xcode_$(XCODE_VERSION).app/Contents/Developer
37-
xcrun simctl list
38-
39-
npm config delete prefix
40-
npm config set prefix $NVM_DIR/versions/node/`node --version`
41-
node --version
42-
43-
npm install -g appium@beta
44-
appium --version
45-
46-
java -version
47-
48-
- task: Gradle@2
49-
inputs:
50-
gradleWrapperFile: 'gradlew'
51-
gradleOptions: '-Xmx3072m'
52-
javaHomeOption: 'JDKVersion'
53-
jdkVersionOption: '1.8'
54-
jdkArchitectureOption: 'x64'
55-
publishJUnitResults: true
56-
tasks: 'build'
57-
options: 'xcuiTest uiAutomationTest -x checkstyleTest -x test -x signMavenJavaPublication'
18+
jobs:
19+
- job: E2E_Tests
20+
timeoutInMinutes: 120
21+
steps:
22+
- task: NodeTool@0
23+
inputs:
24+
versionSpec: '11.x'
25+
26+
- script: |
27+
echo "Configuring Environment"
28+
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;$(ANDROID_EMU_TARGET);$(ANDROID_EMU_TAG);$(ANDROID_EMU_ABI)'
29+
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n "$(ANDROID_EMU_NAME)" -k 'system-images;$(ANDROID_EMU_TARGET);$(ANDROID_EMU_TAG);$(ANDROID_EMU_ABI)' --force
30+
echo $ANDROID_HOME/emulator/emulator -list-avds
31+
32+
echo "Starting emulator"
33+
nohup $ANDROID_HOME/emulator/emulator -avd "$(ANDROID_EMU_NAME)" -no-snapshot > /dev/null 2>&1 &
34+
$ANDROID_HOME/platform-tools/adb wait-for-device
35+
while [[ $? -ne 0 ]]; do sleep 1; $ANDROID_HOME/platform-tools/adb shell pm list packages; done;
36+
$ANDROID_HOME/platform-tools/adb devices
37+
echo "Emulator started"
38+
39+
sudo xcode-select -s /Applications/Xcode_$(XCODE_VERSION).app/Contents/Developer
40+
xcrun simctl list
41+
42+
npm config delete prefix
43+
npm config set prefix $NVM_DIR/versions/node/`node --version`
44+
node --version
45+
46+
npm install -g appium@beta
47+
appium --version
48+
49+
java -version
50+
51+
- task: Gradle@2
52+
inputs:
53+
gradleWrapperFile: 'gradlew'
54+
gradleOptions: '-Xmx3072m'
55+
javaHomeOption: 'JDKVersion'
56+
jdkVersionOption: '1.8'
57+
jdkArchitectureOption: 'x64'
58+
publishJUnitResults: true
59+
tasks: 'build'
60+
options: 'xcuiTest uiAutomationTest -x checkstyleTest -x test -x signMavenJavaPublication'

src/main/java/io/appium/java_client/android/AndroidStartScreenRecordingOptions.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.common.collect.ImmutableMap;
2222

2323
import io.appium.java_client.screenrecording.BaseStartScreenRecordingOptions;
24+
import io.appium.java_client.screenrecording.ScreenRecordingUploadOptions;
2425

2526
import java.time.Duration;
2627
import java.util.Map;
@@ -49,6 +50,14 @@ public AndroidStartScreenRecordingOptions withBitRate(int bitRate) {
4950
this.bitRate = bitRate;
5051
return this;
5152
}
53+
54+
/**
55+
* {@inheritDoc}
56+
*/
57+
@Override
58+
public AndroidStartScreenRecordingOptions withUploadOptions(ScreenRecordingUploadOptions uploadOptions) {
59+
return (AndroidStartScreenRecordingOptions) super.withUploadOptions(uploadOptions);
60+
}
5261

5362
/**
5463
* The video size of the generated media file. The format is WIDTHxHEIGHT.

src/main/java/io/appium/java_client/ios/IOSStartScreenRecordingOptions.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.common.collect.ImmutableMap;
2323

2424
import io.appium.java_client.screenrecording.BaseStartScreenRecordingOptions;
25+
import io.appium.java_client.screenrecording.ScreenRecordingUploadOptions;
2526

2627
import java.time.Duration;
2728
import java.util.Map;
@@ -38,6 +39,14 @@ public static IOSStartScreenRecordingOptions startScreenRecordingOptions() {
3839
return new IOSStartScreenRecordingOptions();
3940
}
4041

42+
/**
43+
* {@inheritDoc}
44+
*/
45+
@Override
46+
public IOSStartScreenRecordingOptions withUploadOptions(ScreenRecordingUploadOptions uploadOptions) {
47+
return (IOSStartScreenRecordingOptions) super.withUploadOptions(uploadOptions);
48+
}
49+
4150
/**
4251
* The video codec type used for encoding of the recorded screen capture.
4352
* Execute `ffmpeg -codecs` in the terminal to see the list of supported video codecs.

src/main/java/io/appium/java_client/screenrecording/BaseScreenRecordingOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public abstract class BaseScreenRecordingOptions<T extends BaseScreenRecordingOp
3333
* for more details.
3434
* @return self instance for chaining.
3535
*/
36-
public T withUploadOptions(ScreenRecordingUploadOptions uploadOptions) {
36+
protected T withUploadOptions(ScreenRecordingUploadOptions uploadOptions) {
3737
this.uploadOptions = checkNotNull(uploadOptions);
3838
//noinspection unchecked
3939
return (T) this;

src/main/java/io/appium/java_client/screenrecording/BaseStartScreenRecordingOptions.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ public abstract class BaseStartScreenRecordingOptions<T extends BaseStartScreenR
2929
private Boolean forceRestart;
3030
private Duration timeLimit;
3131

32-
/**
33-
* The remotePath upload option is the path to the remote location,
34-
* where the resulting video should be uploaded.
35-
* The following protocols are supported: http/https (multipart), ftp.
36-
* Missing value (the default setting) means the content of the resulting
37-
* file should be encoded as Base64 and passed as the endpoint response value, but
38-
* an exception will be thrown if the generated media file is too big to
39-
* fit into the available process memory.
40-
* This option only has an effect if there is a screen recording session in progress
41-
* and forced restart is not enabled (the default setting).
42-
*
43-
* @param uploadOptions see the documentation on {@link ScreenRecordingUploadOptions}
44-
* for more details.
45-
* @return self instance for chaining.
46-
*/
47-
@Override
48-
public T withUploadOptions(ScreenRecordingUploadOptions uploadOptions) {
49-
//noinspection unchecked
50-
return (T) super.withUploadOptions(uploadOptions);
51-
}
52-
5332
/**
5433
* The maximum recording time.
5534
*
@@ -64,8 +43,7 @@ public T withTimeLimit(Duration timeLimit) {
6443

6544
/**
6645
* Whether to ignore the result of previous capture and start a new recording
67-
* immediately. By default the endpoint will try to catch and return the result of
68-
* the previous capture if it's still available.
46+
* immediately.
6947
*
7048
* @return self instance for chaining.
7149
*/
@@ -75,6 +53,17 @@ public T enableForcedRestart() {
7553
return (T) this;
7654
}
7755

56+
/**
57+
* Whether to return silently if there is an active video recording.
58+
*
59+
* @return self instance for chaining.
60+
*/
61+
public T disableForcedRestart() {
62+
this.forceRestart = false;
63+
//noinspection unchecked
64+
return (T) this;
65+
}
66+
7867
@Override
7968
public Map<String, Object> build() {
8069
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();

src/main/java/io/appium/java_client/screenrecording/CanRecordScreen.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,13 @@ public interface CanRecordScreen extends ExecutesMethod {
3131
*
3232
* @param options see the documentation on the {@link BaseStartScreenRecordingOptions}
3333
* descendant for the particular platform.
34-
* @return Base-64 encoded content of the recorded media file or an empty string
35-
* if the file has been successfully uploaded to a remote location (depends on the actual options).
3634
*/
3735
default <T extends BaseStartScreenRecordingOptions> String startRecordingScreen(T options) {
3836
return CommandExecutionHelper.execute(this, startRecordingScreenCommand(options));
3937
}
4038

4139
/**
4240
* Start asynchronous screen recording process with default options.
43-
*
44-
* @return Base-64 encoded content of the recorded media file.
4541
*/
4642
default String startRecordingScreen() {
4743
return this.execute(START_RECORDING_SCREEN).getValue().toString();

src/main/java/io/appium/java_client/windows/WindowsDriver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.appium.java_client.AppiumDriver;
2222
import io.appium.java_client.FindsByWindowsAutomation;
2323
import io.appium.java_client.HidesKeyboardWithKeyName;
24+
import io.appium.java_client.screenrecording.CanRecordScreen;
2425
import io.appium.java_client.service.local.AppiumDriverLocalService;
2526
import io.appium.java_client.service.local.AppiumServiceBuilder;
2627
import org.openqa.selenium.Capabilities;
@@ -32,7 +33,7 @@
3233

3334
public class WindowsDriver<T extends WebElement>
3435
extends AppiumDriver<T> implements PressesKeyCode, HidesKeyboardWithKeyName,
35-
FindsByWindowsAutomation<T> {
36+
FindsByWindowsAutomation<T>, CanRecordScreen {
3637

3738
public WindowsDriver(HttpCommandExecutor executor, Capabilities capabilities) {
3839
super(executor, updateDefaultPlatformName(capabilities, WINDOWS));
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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.windows;
18+
19+
import com.google.common.collect.ImmutableMap;
20+
import io.appium.java_client.screenrecording.BaseStartScreenRecordingOptions;
21+
22+
import java.time.Duration;
23+
import java.util.Map;
24+
25+
import static java.util.Optional.ofNullable;
26+
27+
public class WindowsStartScreenRecordingOptions
28+
extends BaseStartScreenRecordingOptions<WindowsStartScreenRecordingOptions> {
29+
private Integer fps;
30+
private String videoFilter;
31+
private String preset;
32+
private Boolean captureCursor;
33+
private Boolean captureClicks;
34+
private String audioInput;
35+
36+
public static WindowsStartScreenRecordingOptions startScreenRecordingOptions() {
37+
return new WindowsStartScreenRecordingOptions();
38+
}
39+
40+
/**
41+
* The count of frames per second in the resulting video.
42+
* Increasing fps value also increases the size of the resulting
43+
* video file and the CPU usage.
44+
*
45+
* @param fps The actual frames per second value.
46+
* The default value is 15.
47+
* @return self instance for chaining.
48+
*/
49+
public WindowsStartScreenRecordingOptions withFps(int fps) {
50+
this.fps = fps;
51+
return this;
52+
}
53+
54+
/**
55+
* Whether to capture the mouse cursor while recording
56+
* the screen. Disabled by default.
57+
*
58+
* @return self instance for chaining.
59+
*/
60+
public WindowsStartScreenRecordingOptions enableCursorCapture() {
61+
this.captureCursor = true;
62+
return this;
63+
}
64+
65+
/**
66+
* Whether to capture the click gestures while recording
67+
* the screen. Disabled by default.
68+
*
69+
* @return self instance for chaining.
70+
*/
71+
public WindowsStartScreenRecordingOptions enableClicksCapture() {
72+
this.captureClicks = true;
73+
return this;
74+
}
75+
76+
/**
77+
* If provided then the given audio input will be used to record the computer audio
78+
* along with the desktop video. The list of available devices could be retrieved using
79+
* `ffmpeg -list_devices true -f dshow -i dummy` command.
80+
*
81+
* @param audioInput One of valid audio input names listed by ffmpeg
82+
* @return self instance for chaining.
83+
*/
84+
public WindowsStartScreenRecordingOptions withAudioInput(String audioInput) {
85+
this.audioInput = audioInput;
86+
return this;
87+
}
88+
89+
/**
90+
* The video filter spec to apply for ffmpeg.
91+
* See https://trac.ffmpeg.org/wiki/FilteringGuide for more details on the possible values.
92+
* Example: Set it to `scale=ifnot(gte(iw\,1024)\,iw\,1024):-2` in order to limit the video width
93+
* to 1024px. The height will be adjusted automatically to match the actual screen aspect ratio.
94+
*
95+
* @param videoFilter Valid ffmpeg video filter spec string.
96+
* @return self instance for chaining.
97+
*/
98+
public WindowsStartScreenRecordingOptions withVideoFilter(String videoFilter) {
99+
this.videoFilter = videoFilter;
100+
return this;
101+
}
102+
103+
/**
104+
* A preset is a collection of options that will provide a certain encoding speed to compression ratio.
105+
* A slower preset will provide better compression (compression is quality per filesize).
106+
* This means that, for example, if you target a certain file size or constant bit rate, you will
107+
* achieve better quality with a slower preset. Read https://trac.ffmpeg.org/wiki/Encode/H.264
108+
* for more details.
109+
*
110+
* @param preset One of the supported encoding presets. Possible values are:
111+
* - ultrafast
112+
* - superfast
113+
* - veryfast (default)
114+
* - faster
115+
* - fast
116+
* - medium
117+
* - slow
118+
* - slower
119+
* - veryslow
120+
* @return self instance for chaining.
121+
*/
122+
public WindowsStartScreenRecordingOptions withPreset(String preset) {
123+
this.preset = preset;
124+
return this;
125+
}
126+
127+
/**
128+
* The maximum recording time. The default value is 600 seconds (10 minutes).
129+
* The minimum time resolution unit is one second.
130+
*
131+
* @param timeLimit The actual time limit of the recorded video.
132+
* @return self instance for chaining.
133+
*/
134+
@Override
135+
public WindowsStartScreenRecordingOptions withTimeLimit(Duration timeLimit) {
136+
return super.withTimeLimit(timeLimit);
137+
}
138+
139+
@Override
140+
public Map<String, Object> build() {
141+
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
142+
builder.putAll(super.build());
143+
ofNullable(fps).map(x -> builder.put("fps", x));
144+
ofNullable(preset).map(x -> builder.put("preset", x));
145+
ofNullable(videoFilter).map(x -> builder.put("videoFilter", x));
146+
ofNullable(captureClicks).map(x -> builder.put("captureClicks", x));
147+
ofNullable(captureCursor).map(x -> builder.put("captureCursor", x));
148+
ofNullable(audioInput).map(x -> builder.put("audioInput", x));
149+
return builder.build();
150+
}
151+
}

0 commit comments

Comments
 (0)