Skip to content

Commit

Permalink
V2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
A9T9 committed Jan 26, 2018
1 parent a4ea3b4 commit cfb4d0d
Show file tree
Hide file tree
Showing 47 changed files with 5,311 additions and 700 deletions.
13 changes: 13 additions & 0 deletions extension/csv_editor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>CSV Editor - Kantu for Chrome 🤖 Selenium IDE Light</title>
</head>
<body>
<div id="root"></div>
<script src="./csv_editor.js"></script>
</body>
</html>
5 changes: 4 additions & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Kantu Browser Automation",
"description": "Web Browser Automation plus Selenium IDE Light",
"short_name": "Kantu Macros",
"version": "2.0.2",
"version": "2.3.0",

"icons": {
"128": "logo.png"
Expand Down Expand Up @@ -42,6 +42,9 @@
"tabs",
"notifications",
"cookies",
"debugger",
"clipboardRead",
"clipboardWrite",
"file:///*",
"http://*/*",
"https://*/*",
Expand Down
7 changes: 6 additions & 1 deletion src/actions/action_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ const simpleTypes = [
'EDIT_NEW_TEST_CASE',
'ADD_TEST_CASES',
'RENAME_TEST_CASE',
'REMOVE_CURRENT_TEST_CASE',
'REMOVE_TEST_CASE',
'UPDATE_TEST_CASE_STATUS',
'SET_PLAYER_STATE',
'SET_PLAYER_MODE',
'PLAYER_ADD_ERROR_COMMAND_INDEX',

'SET_TEST_SUITES',
'UPDATE_TEST_SUITE',

'CUT_COMMAND',
'COPY_COMMAND',
'PASTE_COMMAND',
Expand All @@ -56,6 +60,7 @@ const simpleTypes = [
'STOP_PLAYING',

'SET_CSV_LIST',
'SET_SCREENSHOT_LIST',

'UPDATE_CONFIG'
].reduce((prev, cur) => {
Expand Down
229 changes: 191 additions & 38 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { pick, until, on, map, compose } from '../common/utils'
import csIpc from '../common/ipc/ipc_cs'
import storage from '../common/storage'
import testCaseModel, { normalizeCommand } from '../models/test_case_model'
import testSuiteModel from '../models/test_suite_model'
import { getPlayer } from '../common/player'
import { getCSVMan } from '../common/csv_man'
import { getScreenshotMan } from '../common/screenshot_man'
import backup from '../common/backup'
import log from '../common/log'

let recordedCount = 0
Expand All @@ -23,13 +26,11 @@ const saveConfig = (function () {
let { config } = getState()
config = config || {}

storage.set('config', config)

const savedSize = config.size ? config.size[config.showSidebar ? 'with_sidebar' : 'standard'] : null
const finalSize = savedSize || (
config.showSidebar
? {
width: 720,
width: 850,
height: 775
} : {
width: 520,
Expand All @@ -39,27 +40,18 @@ const saveConfig = (function () {

if (finalSize.width !== lastSize.width ||
finalSize.height !== lastSize.height) {
until('find app dom', () => {
const $app = document.querySelector('.app')
return {
pass: !!$app,
result: $app
}
}, 100)
.then($app => {
if (config.showSidebar) {
$app.classList.add('with-sidebar')
} else {
$app.classList.remove('with-sidebar')
storage.get('config')
.then(oldConfig => {
if (oldConfig.showSidebar === config.showSidebar) return

if (finalSize.width !== window.outerWidth || finalSize.height !== window.outerHeight) {
csIpc.ask('PANEL_RESIZE_WINDOW', { size: finalSize })
}
})

if (finalSize.width !== window.outerWidth || finalSize.height !== window.outerHeight) {
csIpc.ask('PANEL_RESIZE_WINDOW', { size: finalSize })
}

lastSize = finalSize
}

storage.set('config', config)
lastSize = finalSize
}
})()

Expand Down Expand Up @@ -158,8 +150,8 @@ export function insertCommand (cmdObj, index) {
return {
type: T.INSERT_COMMAND,
data: {
command: cmdObj,
index: index
index,
command: cmdObj
},
post: saveEditing
}
Expand Down Expand Up @@ -337,48 +329,86 @@ export function addTestCases (tcs) {
}
}

export function renameTestCase (name) {
export function renameTestCase (name, tcId) {
return (dispatch, getState) => {
const state = getState()
const id = state.editor.editing.meta.src.id
const tc = state.editor.testCases.find(tc => tc.id === id)
const sameName = state.editor.testCases.find(tc => tc.id !== id && tc.name === name)
const state = getState()
const editingId = state.editor.editing.meta.src.id
const tc = state.editor.testCases.find(tc => tc.id === tcId)
const sameName = state.editor.testCases.find(tc => tc.name === name)

if (!tc) {
return Promise.reject(new Error(`No test case found with id '${tcId}'!`))
}

if (sameName) {
return Promise.reject(new Error('The test case name already exists!'))
}

return testCaseModel.update(id, {...tc, name})
.then(() => {
return testCaseModel.update(tcId, {...tc, name})
.then(() => {
if (editingId === tcId) {
dispatch({
type: T.RENAME_TEST_CASE,
data: name,
post: saveEditing
})
})
}
})
}
}

export function removeCurrentTestCase () {
export function removeTestCase (tcId) {
return (dispatch, getState) => {
const state = getState()
const id = state.editor.editing.meta.src.id
const curId = state.editor.editing.meta.src.id
const tss = state.editor.testSuites.filter(ts => {
return ts.cases.find(m => m.testCaseId === tcId)
})

return testCaseModel.remove(id)
if (tss.length > 0) {
return Promise.reject(new Error(`Can't delete this macro for now, it's currently used in following test suites: ${tss.map(item => item.name)}`))
}

return testCaseModel.remove(tcId)
.then(() => {
dispatch({
type: T.REMOVE_CURRENT_TEST_CASE,
data: null,
type: T.REMOVE_TEST_CASE,
data: {
isCurrent: curId === tcId
},
post: saveEditing
})
})
.catch(e => log.error(e.stack))
}
}

export function removeCurrentTestCase () {
return (dispatch, getState) => {
const state = getState()
const id = state.editor.editing.meta.src.id

return removeTestCase(id)(dispatch, getState)
}
}

// Note: duplicate current editing and save to another
export function duplicateTestCase (newTestCaseName) {
return saveEditingAsNew(newTestCaseName)
export function duplicateTestCase (newTestCaseName, tcId) {
return (dispatch, getState) => {
const state = getState()
const tc = state.editor.testCases.find(tc => tc.id === tcId)
const sameName = state.editor.testCases.find(tc => tc.name === newTestCaseName)

if (!tc) {
return Promise.reject(new Error(`No test case found with id '${tcId}'!`))
}

if (sameName) {
return Promise.reject(new Error('The test case name already exists!'))
}

return testCaseModel.insert({ ...tc, name: newTestCaseName })
}
}

export function setPlayerState (obj) {
Expand Down Expand Up @@ -463,6 +493,7 @@ export function playerPlay (options) {
'!MACRONAME': macroName,
'!TIMEOUT_PAGELOAD': parseInt(config.timeoutPageLoad, 10),
'!TIMEOUT_WAIT': parseInt(config.timeoutElement, 10),
'!TIMEOUT_MACRO': parseInt(config.timeoutMacro, 10),
'!REPLAYSPEED': ({
'0': 'FAST',
'0.3': 'MEDIUM',
Expand Down Expand Up @@ -499,3 +530,125 @@ export function listCSV () {
})
}
}

export function listScreenshots () {
return (dispatch, getState) => {
const man = getScreenshotMan()

man.list().then(list => {
list.reverse()

return list.map(item => ({
name: item.fileName,
url: man.getLink(item.fileName),
createTime: new Date(item.lastModified)
}))
}).then(list => {
dispatch({
type: T.SET_SCREENSHOT_LIST,
data: list
})
})
}
}

export function setTestSuites (tss) {
return {
type: T.SET_TEST_SUITES,
data: tss
}
}

export function addTestSuite (ts) {
return (dispatch, getState) => {
return testSuiteModel.insert(ts)
}
}

export function addTestSuites (tss) {
return (dispatch, getState) => {
const state = getState()
// const testCases = state.editor.testCases
const validTss = tss
// const failTcs = tcs.filter(tc => testCases.find(tcc => tcc.name === tc.name))

const passCount = validTss.length
const failCount = tss.length - passCount

if (passCount === 0) {
return Promise.resolve({ passCount, failCount, failTss: [] })
}

return testSuiteModel.bulkInsert(validTss)
.then(() => ({ passCount, failCount, failTss: [] }))
}
}

export function updateTestSuite (id, data) {
return (dispatch, getState) => {
const state = getState()
const ts = state.editor.testSuites.find(ts => ts.id === id)

const revised = {
...ts,
...(typeof data === 'function' ? data(ts) : data)
}

dispatch({
type: T.UPDATE_TEST_SUITE,
data: {
id: id,
updated: revised
}
})

return testSuiteModel.update(id, revised)
}
}

export function removeTestSuite (id) {
return (dispatch, getState) => {
return testSuiteModel.remove(id)
}
}

export function setPlayerMode (mode) {
return {
type: T.SET_PLAYER_STATE,
data: { mode }
}
}

export function runBackup () {
return (dispatch, getState) => {
const { config, editor } = getState()
const {
autoBackupTestCases,
autoBackupTestSuites,
autoBackupScreenshots,
autoBackupCSVFiles
} = config

return Promise.all([
getCSVMan().list(),
getScreenshotMan().list()
])
.then(([csvs, screenshots]) => {
return backup({
csvs,
screenshots,
testCases: editor.testCases,
testSuites: editor.testSuites,
backup: {
testCase: autoBackupTestCases,
testSuite: autoBackupTestSuites,
screenshot: autoBackupScreenshots,
csv: autoBackupCSVFiles
}
})
})
.catch(e => {
log.error(e.stack)
})
}
}

0 comments on commit cfb4d0d

Please sign in to comment.