Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions app/common/renderer/actions/SessionBuilder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash';
import sanitize from 'sanitize-filename';

import {
SAVED_SESSIONS,
Expand All @@ -7,7 +8,12 @@ import {
SESSION_SERVER_TYPE,
VISIBLE_PROVIDERS,
} from '../../shared/setting-defs.js';
import {SERVER_TYPES, SESSION_BUILDER_TABS} from '../constants/session-builder.js';
import {
DEFAULT_SESSION_NAME,
SERVER_TYPES,
SESSION_BUILDER_TABS,
SESSION_FILE_VERSIONS,
} from '../constants/session-builder.js';
import {APP_MODE} from '../constants/session-inspector.js';
import {DEFAULT_SERVER_PROPS} from '../constants/webdriver.js';
import i18n from '../i18next.js';
Expand All @@ -18,10 +24,11 @@ import {
fetchSessionInformation,
formatSeleniumGridSessions,
} from '../utils/attaching-to-session.js';
import {downloadFile, parseSessionFileContents} from '../utils/file-handling.js';
import {downloadFile} from '../utils/file-handling.js';
import {log} from '../utils/logger.js';
import {notification} from '../utils/notification.js';
import {addVendorPrefixes} from '../utils/other.js';
import {parseSessionFileContents} from '../utils/sessionfile-parsing.js';
import {quitSession, setSessionDetails} from './SessionInspector.js';

export const NEW_SESSION_REQUESTED = 'NEW_SESSION_REQUESTED';
Expand Down Expand Up @@ -72,8 +79,6 @@ export const SET_CAPABILITY_NAME_ERROR = 'SET_CAPABILITY_NAME_ERROR';
export const SET_STATE_FROM_URL = 'SET_STATE_FROM_URL';
export const SET_STATE_FROM_FILE = 'SET_STATE_FROM_FILE';

const APPIUM_SESSION_FILE_VERSION = '1.0';

const CAPS_NEW_COMMAND = 'appium:newCommandTimeout';
const CAPS_CONNECT_HARDWARE_KEYBOARD = 'appium:connectHardwareKeyboard';
const CAPS_NATIVE_WEB_SCREENSHOT = 'appium:nativeWebScreenshot';
Expand Down Expand Up @@ -624,6 +629,11 @@ export function setStateFromSessionFile(sessionFileString) {
});
return;
}
sessionJSON.serverType = Object.keys(sessionJSON.server).find(
(type) => type !== SERVER_TYPES.ADVANCED,
);
sessionJSON.visibleProviders =
sessionJSON.serverType !== SERVER_TYPES.REMOTE ? [sessionJSON.serverType] : [];
dispatch({type: SET_STATE_FROM_FILE, sessionJSON});
switchTabs(SESSION_BUILDER_TABS.CAPS_BUILDER)(dispatch, getState);
};
Expand All @@ -635,17 +645,22 @@ export function setStateFromSessionFile(sessionFileString) {
export function saveSessionAsFile() {
return (_dispatch, getState) => {
const state = getState().builder;
const sessionName = state.capsName?.trim() || DEFAULT_SESSION_NAME;
const filteredServer = {
[state.serverType]: state.server[state.serverType],
[SERVER_TYPES.ADVANCED]: state.server[SERVER_TYPES.ADVANCED],
};
const sessionFileDetails = {
version: APPIUM_SESSION_FILE_VERSION,
version: SESSION_FILE_VERSIONS.LATEST,
name: sessionName,
server: filteredServer,
caps: state.caps.map((cap) => _.omit(cap, 'id')),
server: state.server,
serverType: state.serverType,
visibleProviders: state.visibleProviders,
};
const href = `data:text/json;charset=utf-8,${encodeURIComponent(
JSON.stringify(sessionFileDetails, null, 2),
)}`;
const fileName = `${state.serverType}.appiumsession`;
const escapedName = sanitize(sessionName, {replacement: '_'});
const fileName = `${escapedName}.appiumsession`;
downloadFile(href, fileName);
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Checkbox, Col, Collapse, Form, Input, Row} from 'antd';

import {SERVER_TYPES} from '../../../constants/session-builder.js';
import {SERVER_ADVANCED_PARAMS, SERVER_TYPES} from '../../../constants/session-builder.js';
import styles from './ServerDetails.module.css';

const AdvancedServerParams = ({server, setServerParam, serverType, t}) => (
Expand All @@ -20,7 +20,7 @@ const AdvancedServerParams = ({server, setServerParam, serverType, t}) => (
checked={!!server.advanced.allowUnauthorized}
onChange={(e) =>
setServerParam(
'allowUnauthorized',
SERVER_ADVANCED_PARAMS.ALLOW_UNAUTHORIZED,
e.target.checked,
SERVER_TYPES.ADVANCED,
)
Expand All @@ -36,7 +36,11 @@ const AdvancedServerParams = ({server, setServerParam, serverType, t}) => (
<Checkbox
checked={!!server.advanced.useProxy}
onChange={(e) =>
setServerParam('useProxy', e.target.checked, SERVER_TYPES.ADVANCED)
setServerParam(
SERVER_ADVANCED_PARAMS.USE_PROXY,
e.target.checked,
SERVER_TYPES.ADVANCED,
)
}
>
{t('Use Proxy')}
Expand All @@ -48,7 +52,11 @@ const AdvancedServerParams = ({server, setServerParam, serverType, t}) => (
<Input
disabled={!server.advanced.useProxy}
onChange={(e) =>
setServerParam('proxy', e.target.value, SERVER_TYPES.ADVANCED)
setServerParam(
SERVER_ADVANCED_PARAMS.PROXY,
e.target.value,
SERVER_TYPES.ADVANCED,
)
}
placeholder={t('Proxy URL')}
value={server.advanced.proxy}
Expand Down
14 changes: 14 additions & 0 deletions app/common/renderer/constants/session-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ export const SESSION_BUILDER_TABS = {
ATTACH_TO_SESSION: 'attach',
};

export const SESSION_FILE_VERSIONS = {
V1: '1.0',
V2: 2,
LATEST: 2,
};

export const DEFAULT_SESSION_NAME = '(unnamed)';

export const SERVER_TYPES = {
LOCAL: 'local',
REMOTE: 'remote',
Expand Down Expand Up @@ -46,6 +54,12 @@ export const PROVIDER_VALUES = {

export const ADD_CLOUD_PROVIDER_TAB_KEY = 'addCloudProvider';

export const SERVER_ADVANCED_PARAMS = {
ALLOW_UNAUTHORIZED: 'allowUnauthorized',
PROXY: 'proxy',
USE_PROXY: 'useProxy',
};

export const CAPABILITY_TYPES = {
TEXT: 'text',
BOOL: 'boolean',
Expand Down
7 changes: 6 additions & 1 deletion app/common/renderer/reducers/SessionBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,17 @@ export default function builder(state = INITIAL_STATE, action) {
enabled: true,
...cap,
})),
// reset capsName since we now have an unnamed session
capsName: null,
server: {
...state.server,
...action.sessionJSON.server,
},
serverType: action.sessionJSON.serverType,
visibleProviders: action.sessionJSON.visibleProviders || [],
visibleProviders: _.union(
state.visibleProviders,
action.sessionJSON.visibleProviders || [],
),
};

default:
Expand Down
34 changes: 0 additions & 34 deletions app/common/renderer/utils/file-handling.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import _ from 'lodash';

import {CAPABILITY_TYPES, SERVER_TYPES} from '../constants/session-builder.js';

export function downloadFile(href, filename) {
let element = document.createElement('a');
element.setAttribute('href', href);
Expand Down Expand Up @@ -34,33 +30,3 @@ export async function readTextFromUploadedFiles(fileList) {
});
return await Promise.all(fileReaderPromise);
}

export function parseSessionFileContents(sessionFileString) {
try {
const sessionJSON = JSON.parse(sessionFileString);
for (const sessionProp of ['version', 'caps', 'serverType']) {
if (!(sessionProp in sessionJSON)) {
return null;
}
}
if (!_.values(SERVER_TYPES).includes(sessionJSON.serverType)) {
return null;
} else if (!_.isArray(sessionJSON.caps)) {
return null;
} else {
for (const cap of sessionJSON.caps) {
for (const capProp of ['type', 'name', 'value']) {
if (!(capProp in cap)) {
return null;
}
}
if (!_.values(CAPABILITY_TYPES).includes(cap.type)) {
return null;
}
}
}
return sessionJSON;
} catch {
return null;
}
}
Loading