Skip to content

Commit

Permalink
refactor(java): ♻️ minor refactoring done for video record
Browse files Browse the repository at this point in the history
  • Loading branch information
WasiqB committed Oct 24, 2023
1 parent c8b9ca5 commit 3df6fe3
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 98 deletions.
2 changes: 1 addition & 1 deletion core-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven-checkstyle-plugin.version>3.3.0</maven-checkstyle-plugin.version>
<codestyle.version>1.1.0</codestyle.version>
<checkstyle.version>10.12.3</checkstyle.version>
<checkstyle.version>10.12.4</checkstyle.version>
<aspectj.version>1.9.20.1</aspectj.version>
<suite-name>testng</suite-name>
<suite-xml>test-suites/${suite-name}.xml</suite-xml>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static com.github.wasiqb.boyka.enums.DeviceType.CLOUD;
import static com.github.wasiqb.boyka.enums.ListenerType.DEVICE_ACTION;
import static com.github.wasiqb.boyka.enums.Message.NO_KEYBOARD_ERROR;
import static com.github.wasiqb.boyka.enums.Message.RECORDING_NOT_SUPPORTED;
import static com.github.wasiqb.boyka.enums.PlatformType.ANDROID;
import static com.github.wasiqb.boyka.enums.PlatformType.IOS;
import static com.github.wasiqb.boyka.enums.PlatformType.WEB;
Expand Down Expand Up @@ -92,27 +91,29 @@ public boolean isKeyboardVisible () {
@Override
public void startRecording () {
final var platform = getSession ().getPlatformType ();
checkVideoSupported (platform);
final var mobileSetting = getSession ().getMobileSetting ()
.getDevice ();
final var setting = mobileSetting.getVideo ();
if (setting.isEnabled () && mobileSetting.getType () != CLOUD) {
final var screen = (CanRecordScreen) getSession ().getDriver ();
startRecording (screen, setting, platform);
if (platform == ANDROID || platform == IOS) {
final var mobileSetting = getSession ().getMobileSetting ()
.getDevice ();
final var setting = mobileSetting.getVideo ();
if (mobileSetting.getType () != CLOUD && setting.isEnabled ()) {
final var screen = (CanRecordScreen) getSession ().getDriver ();
startRecording (screen, setting, platform);
}
}
}

@Override
public void stopRecording () {
final var platform = getSession ().getPlatformType ();
checkVideoSupported (platform);
final var mobileSetting = getSession ().getMobileSetting ()
.getDevice ();
final var setting = mobileSetting.getVideo ();
if (setting.isEnabled () && mobileSetting.getType () != CLOUD) {
final var screen = (CanRecordScreen) getSession ().getDriver ();
final var content = stopRecording (screen, platform);
saveVideo (content);
if (platform == ANDROID || platform == IOS) {
final var mobileSetting = getSession ().getMobileSetting ()
.getDevice ();
final var setting = mobileSetting.getVideo ();
if (mobileSetting.getType () != CLOUD && setting.isEnabled ()) {
final var screen = (CanRecordScreen) getSession ().getDriver ();
final var content = stopRecording (screen, platform);
saveVideo (content);
}
}
}

Expand All @@ -123,12 +124,6 @@ private void checkKeyboardSupported () {
}
}

private void checkVideoSupported (final PlatformType platform) {
if (platform != ANDROID && platform != IOS) {
throwError (RECORDING_NOT_SUPPORTED, platform);
}
}

private AndroidStartScreenRecordingOptions getAndroidRecordOptions (final VideoSetting setting) {
final var androidSetting = setting.getAndroid ();
final var options = AndroidStartScreenRecordingOptions.startScreenRecordingOptions ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ public enum Message {
* Protocol is required for host name
*/
PROTOCOL_REQUIRED_FOR_HOST ("Protocol is required for host ({0})..."),
/**
* Video recording is not supported.
*/
RECORDING_NOT_SUPPORTED ("Video recording is not supported for ({0}) platform..."),
/**
* Schema validation assert failure
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.wasiqb.boyka.testng.ui.saucedemo;

import static com.github.wasiqb.boyka.actions.device.DeviceActions.onDevice;
import static com.github.wasiqb.boyka.actions.drivers.ContextActions.withContext;
import static com.github.wasiqb.boyka.actions.drivers.DriverActions.withDriver;
import static com.github.wasiqb.boyka.actions.drivers.WindowActions.onWindow;
Expand Down Expand Up @@ -46,6 +47,7 @@ public void afterMethod (final ITestResult result) {
@Parameters ({ "platformType", "driverKey" })
public void setupTestClass (final PlatformType platformType, final String driverKey) {
createSession (format ("SauceDemoTest-{0}", platformType), platformType, driverKey);
onDevice ().startRecording ();
this.sauceDemo = new SauceDemoActions ();
}

Expand All @@ -54,6 +56,7 @@ public void setupTestClass (final PlatformType platformType, final String driver
*/
@AfterClass (description = "Tear down test class", alwaysRun = true)
public void tearDownTestClass () {
onDevice ().stopRecording ();
withDriver ().saveLogs ();
clearSession ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static com.github.wasiqb.boyka.actions.elements.ClickableActions.withMouse;
import static com.github.wasiqb.boyka.actions.elements.ElementActions.onElement;
import static com.github.wasiqb.boyka.actions.elements.TextBoxActions.onTextBox;
import static com.github.wasiqb.boyka.enums.PlatformType.WEB;
import static com.github.wasiqb.boyka.manager.ParallelSession.clearSession;
import static com.github.wasiqb.boyka.manager.ParallelSession.createSession;
import static com.github.wasiqb.boyka.testng.ui.theinternet.pages.LoginPage.loginPage;
Expand Down Expand Up @@ -67,9 +66,7 @@ public void afterMethod (final ITestResult result) {
public void setupClass (final PlatformType platformType, final String driverKey) {
createSession ("LoginTest", platformType, driverKey);
this.platformType = platformType;
if (platformType != WEB) {
onDevice ().startRecording ();
}
onDevice ().startRecording ();
navigate ().to (URL);
}

Expand All @@ -78,9 +75,7 @@ public void setupClass (final PlatformType platformType, final String driverKey)
*/
@AfterClass (description = "Tear down test class")
public void tearDownClass () {
if (this.platformType != WEB) {
onDevice ().stopRecording ();
}
onDevice ().stopRecording ();
clearSession ();
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"@commitlint/config-conventional": "^18.0.0",
"@lerna/child-process": "^7.4.1",
"@lerna/version": "^6.6.2",
"@types/node": "^20.8.7",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"@types/node": "^20.8.8",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"commitlint": "^18.0.0",
"eslint": "^8.52.0",
"eslint-config-google": "^0.14.0",
Expand Down
Loading

0 comments on commit 3df6fe3

Please sign in to comment.