-
-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
add support of mobitru screen recording feature #5307
Changes from 3 commits
2905c08
cd1b809
6c71368
e4e098f
f7b2410
4238f96
b510afa
ffb0516
3ebf448
f616f60
f54343c
ab33d51
4ac8857
64c6474
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2019-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.vividus.mobitru.client.model; | ||
|
||
public class ScreenRecording | ||
{ | ||
private String recordingId; | ||
|
||
public String getRecordingId() | ||
{ | ||
return recordingId; | ||
} | ||
|
||
public void setRecordingId(String recordingId) | ||
{ | ||
this.recordingId = recordingId; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "ScreenRecording{id='" + recordingId + '}'; | ||
Check warning on line 36 in vividus-plugin-mobitru/src/main/java/org/vividus/mobitru/client/model/ScreenRecording.java
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Copyright 2019-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.vividus.mobitru.recording; | ||
|
||
import com.google.common.eventbus.Subscribe; | ||
|
||
import org.jbehave.core.annotations.AfterScenario; | ||
import org.jbehave.core.annotations.BeforeScenario; | ||
import org.jbehave.core.annotations.ScenarioType; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.vividus.mobitru.client.MobitruFacade; | ||
import org.vividus.mobitru.client.exception.MobitruOperationException; | ||
import org.vividus.reporter.event.IAttachmentPublisher; | ||
import org.vividus.selenium.IWebDriverProvider; | ||
import org.vividus.selenium.event.BeforeWebDriverQuitEvent; | ||
import org.vividus.selenium.event.WebDriverCreateEvent; | ||
import org.vividus.testcontext.TestContext; | ||
|
||
public class MobitruRecordingListener | ||
{ | ||
private static final String KEY = "mobitruDeviceId"; | ||
private static final Logger LOGGER = LoggerFactory.getLogger(MobitruRecordingListener.class); | ||
|
||
private final MobitruFacade mobitruFacade; | ||
private final IAttachmentPublisher attachmentPublisher; | ||
private final IWebDriverProvider webDriverProvider; | ||
private boolean enableRecording; | ||
private final TestContext testContext; | ||
|
||
public MobitruRecordingListener(MobitruFacade mobitruFacade, IAttachmentPublisher attachmentPublisher, | ||
TestContext testContext, IWebDriverProvider webDriverProvider) | ||
{ | ||
this.mobitruFacade = mobitruFacade; | ||
this.attachmentPublisher = attachmentPublisher; | ||
this.testContext = testContext; | ||
this.webDriverProvider = webDriverProvider; | ||
} | ||
|
||
@BeforeScenario(uponType = ScenarioType.ANY) | ||
public void startRecordingBeforeScenario() | ||
{ | ||
//perform start recording if a web driver session is already exist, | ||
//which means onSessionStart will be not executed | ||
valfirst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (webDriverProvider.isWebDriverInitialized()) | ||
{ | ||
startRecordingIfEnabled(); | ||
Check warning on line 61 in vividus-plugin-mobitru/src/main/java/org/vividus/mobitru/recording/MobitruRecordingListener.java
|
||
} | ||
} | ||
Check warning on line 63 in vividus-plugin-mobitru/src/main/java/org/vividus/mobitru/recording/MobitruRecordingListener.java
|
||
|
||
@Subscribe | ||
public void onSessionStart(WebDriverCreateEvent event) | ||
{ | ||
startRecordingIfEnabled(); | ||
} | ||
|
||
@Subscribe | ||
public void onSessionStop(BeforeWebDriverQuitEvent event) | ||
{ | ||
publishRecordingIfEnabled(); | ||
} | ||
|
||
@AfterScenario(uponType = ScenarioType.ANY) | ||
public void publishRecordingAfterScenario() | ||
{ | ||
//perform publish if a web driver session is still exist, | ||
//which means onSessionStop method was not executed | ||
if (webDriverProvider.isWebDriverInitialized()) | ||
valfirst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
publishRecordingIfEnabled(); | ||
Check warning on line 84 in vividus-plugin-mobitru/src/main/java/org/vividus/mobitru/recording/MobitruRecordingListener.java
|
||
} | ||
} | ||
Check warning on line 86 in vividus-plugin-mobitru/src/main/java/org/vividus/mobitru/recording/MobitruRecordingListener.java
|
||
|
||
private void startRecordingIfEnabled() | ||
{ | ||
if (enableRecording) | ||
{ | ||
String deviceId = getDeviceId(); | ||
try | ||
{ | ||
mobitruFacade.startDeviceScreenRecording(deviceId); | ||
} | ||
catch (MobitruOperationException e) | ||
{ | ||
LOGGER.atWarn() | ||
.addArgument(deviceId) | ||
.setCause(e) | ||
.log("Unable to start recording on device with UUID {}"); | ||
} | ||
} | ||
} | ||
|
||
private void publishRecordingIfEnabled() | ||
{ | ||
if (enableRecording) | ||
{ | ||
String deviceId = getDeviceId(); | ||
try | ||
{ | ||
String recordingId = mobitruFacade.stopDeviceScreenRecording(deviceId); | ||
byte[] recording = mobitruFacade.downloadDeviceScreenRecording(recordingId); | ||
String attachmentName = String.format("mobitru_session_recording_%s.mp4", recordingId); | ||
attachmentPublisher.publishAttachment(recording, attachmentName); | ||
} | ||
catch (MobitruOperationException e) | ||
{ | ||
LOGGER.atWarn() | ||
.addArgument(deviceId) | ||
.setCause(e) | ||
.log("Unable to stop or download recording on device with UUID {}"); | ||
} | ||
} | ||
} | ||
|
||
public void setEnableRecording(boolean enableRecording) | ||
{ | ||
this.enableRecording = enableRecording; | ||
} | ||
|
||
private String getDeviceId() | ||
{ | ||
return testContext.get(KEY); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in facade it makes sense to have a single method
stopDeviceScreenRecording
that will return a POJO with the recording ID and its binary contentThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean to add
bute[] content
field to org.vividus.mobitru.client.model.ScreenRecording and then specify it in the facade method?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about Mobitru REST API and its mapping to model
ScreenRecording
, probably there should be another POJOThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but downloadDeviceScreenRecording API call just returns a byte array.
how this another POJO should look like in this case ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just create a new object in the code from the results of 2 API calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean that I should have 2 screen recording classes?
because, right now, I already have org.vividus.mobitru.client.model.ScreenRecording, which is using as DTO for result of stopRecording API and it contains recordingId only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done