Skip to content

Commit 3d7138f

Browse files
committed
added persistSession to suite
1 parent 6a01b1b commit 3d7138f

File tree

19 files changed

+92
-68
lines changed

19 files changed

+92
-68
lines changed

packages/selenium-ide/src/neo/__test__/models/Suite.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,32 @@ describe("Suite model", () => {
5757
it("should initiate as a sequential suite", () => {
5858
const suite = new Suite();
5959
expect(suite.isParallel).toBeFalsy();
60+
expect(suite.persistSession).toBeFalsy();
6061
});
6162
it("should set the suite to parallel", () => {
6263
const suite = new Suite();
6364
suite.setParallel(true);
6465
expect(suite.isParallel).toBeTruthy();
6566
});
67+
it("should set the suite to unsafe", () => {
68+
const suite = new Suite();
69+
suite.setPersistSession(true);
70+
expect(suite.persistSession).toBeTruthy();
71+
});
72+
it("should not be able to set a parallel suite unsafe", () => {
73+
const suite = new Suite();
74+
suite.setParallel(true);
75+
suite.setPersistSession(true);
76+
expect(suite.persistSession).toBeFalsy();
77+
});
78+
it("should make a suite safe if it was made parallel", () => {
79+
const suite = new Suite();
80+
suite.setPersistSession(true);
81+
expect(suite.persistSession).toBeTruthy();
82+
suite.setParallel(true);
83+
expect(suite.isParallel).toBeTruthy();
84+
expect(suite.persistSession).toBeFalsy();
85+
});
6686
it("should add a new Test Case", () => {
6787
const store = new ProjectStore();
6888
const suite = new Suite();

packages/selenium-ide/src/neo/components/SuiteSettings/index.jsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,31 @@ import ModalHeader from "../ModalHeader";
2323
import Input from "../FormInput";
2424
import FlatButton from "../FlatButton";
2525
import Checkbox from "../Checkbox";
26+
import Markdown from "../Markdown";
2627

2728
export default class SuiteSettings extends React.Component {
2829
constructor(props) {
2930
super(props);
3031
this.state = {
3132
timeout: props.timeout ? props.timeout : "",
32-
isParallel: !!props.isParallel
33+
isParallel: !!props.isParallel,
34+
persistSession: !!props.persistSession
3335
};
3436
}
3537
static propTypes = {
3638
isEditing: PropTypes.bool,
3739
timeout: PropTypes.number,
3840
isParallel: PropTypes.bool,
41+
persistSession: PropTypes.bool,
3942
submit: PropTypes.func,
4043
cancel: PropTypes.func
4144
};
4245
componentWillReceiveProps(nextProps) {
4346
if (!this.props.isEditing && nextProps.isEditing) {
4447
this.setState({
4548
timeout: nextProps.timeout,
46-
isParallel: nextProps.isParallel
49+
isParallel: nextProps.isParallel,
50+
persistSession: nextProps.persistSession
4751
});
4852
}
4953
}
@@ -57,7 +61,13 @@ export default class SuiteSettings extends React.Component {
5761
isParallel: e.target.checked
5862
});
5963
}
64+
onPersistSessionChange(e) {
65+
this.setState({
66+
persistSession: e.target.checked
67+
});
68+
}
6069
render() {
70+
const persistSession = !this.state.isParallel && this.state.persistSession;
6171
return (
6272
<Modal className="suite-settings-dialog" isOpen={this.props.isEditing} onRequestClose={this.props.cancel}>
6373
<form onSubmit={(e) => { e.preventDefault(); }} style={{
@@ -67,10 +77,20 @@ export default class SuiteSettings extends React.Component {
6777
<div className="form-contents">
6878
<Input name="suite-timeout" type="number" label="Timeout (seconds)" placeholder={DEFAULT_TIMEOUT} value={this.state.timeout} width={130} onChange={this.onTimeoutChange.bind(this)} />
6979
<Checkbox label="Run in parallel" checked={this.state.isParallel} width={130} onChange={this.onIsParallelChange.bind(this)} />
80+
<Checkbox label="Persist session" checked={persistSession} disabled={this.state.isParallel} width={130} onChange={this.onPersistSessionChange.bind(this)} />
81+
<div>(not recommended)</div>
82+
{persistSession && <Markdown className="markdown">
83+
{"Persisting session will not reset the WebDriver session and variables between test run, which will result in [\"non-idempotent non-isolated\"](http://jasonpolites.github.io/tao-of-testing/ch4-1.1.html#rule-10-ensure-tests-are-isolated-and-idempotent) tests that are difficult to debug."}
84+
</Markdown>}
7085
</div>
7186
<span className="right">
7287
<FlatButton onClick={this.props.cancel}>Cancel</FlatButton>
73-
<FlatButton type="submit" onClick={() => {this.props.submit({ timeout: parseInt(this.state.timeout) || DEFAULT_TIMEOUT, isParallel: this.state.isParallel });}} style={{
88+
<FlatButton type="submit" onClick={() => {this.props.submit({
89+
timeout: parseInt(this.state.timeout) || DEFAULT_TIMEOUT,
90+
isParallel: this.state.isParallel,
91+
persistSession: this.state.persistSession
92+
});
93+
}} style={{
7494
marginRight: "0"
7595
}}>Submit</FlatButton>
7696
</span>

packages/selenium-ide/src/neo/containers/Modal/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export default class Modal extends Component {
6363
isEditing={ModalState.suiteSettingsState.editing}
6464
timeout={ModalState.suiteSettingsState.timeout}
6565
isParallel={ModalState.suiteSettingsState.isParallel}
66+
persistSession={ModalState.suiteSettingsState.persistSession}
6667
submit={ModalState.suiteSettingsState ? ModalState.suiteSettingsState.done : null}
6768
cancel={ModalState.cancelSuiteSettings}
6869
/>

packages/selenium-ide/src/neo/models/Suite.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default class Suite {
2626
@observable name = null;
2727
@observable timeout = DEFAULT_TIMEOUT;
2828
@observable isParallel = false;
29+
@observable persistSession = false;
2930
@observable _tests = [];
3031

3132
constructor(id = uuidv4(), name = "Untitled Suite") {
@@ -58,6 +59,16 @@ export default class Suite {
5859

5960
@action.bound setParallel(parallel) {
6061
this.isParallel = !!parallel;
62+
if (this.isParallel) {
63+
// setting directly because setPersistSession is locked
64+
this.persistSession = false;
65+
}
66+
}
67+
68+
@action.bound setPersistSession(persistSession) {
69+
if (!this.isParallel) {
70+
this.persistSession = persistSession;
71+
}
6172
}
6273

6374
@action.bound addTestCase(test) {
@@ -88,6 +99,7 @@ export default class Suite {
8899
return {
89100
id: this.id,
90101
name: this.name,
102+
persistSession: this.persistSession,
91103
parallel: this.isParallel,
92104
timeout: this.timeout,
93105
tests: this._tests.map(t => t.id)

packages/selenium-ide/src/neo/stores/view/ModalState.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@ class ModalState {
124124
this.suiteSettingsState = {
125125
editing: true,
126126
isParallel: suite.isParallel,
127+
persistSession: suite.persistSession,
127128
timeout: suite.timeout,
128-
done: ({ isParallel, timeout }) => {
129+
done: ({ isParallel, persistSession, timeout }) => {
129130
suite.setTimeout(timeout);
130131
suite.setParallel(isParallel);
132+
suite.setPersistSession(persistSession);
131133
this.cancelSuiteSettings();
132134
}
133135
};

packages/selenium-side-runner/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"commander": "^2.12.2",
3131
"global-npm": "^0.3.0",
3232
"jest": "^23.1.0",
33-
"jest-environment-selenium": "^1.0.0",
33+
"jest-environment-selenium": "^1.1.0",
3434
"js-beautify": "^1.7.5",
3535
"js-yaml": "^3.10.0",
3636
"rimraf": "^2.6.2",

packages/selenium-side-runner/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ function runProject(project) {
115115
project.code.suites.forEach(suite => {
116116
if (!suite.tests) {
117117
// not parallel
118-
writeJSFile(path.join(projectPath, suite.name), `// This file was generated using Selenium IDE\nconst tests = require("./commons.js");${suite.code}`);
118+
const cleanup = suite.persistSession ? "" : "beforeEach(() => {vars = {};});afterEach(async () => (cleanup()));";
119+
writeJSFile(path.join(projectPath, suite.name), `// This file was generated using Selenium IDE\nconst tests = require("./commons.js");${suite.code}${cleanup}`);
119120
} else if (suite.tests.length) {
120121
fs.mkdirSync(path.join(projectPath, suite.name));
121122
// parallel suite

packages/selenium-side-runner/yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,9 +2479,9 @@ jest-environment-node@^23.1.0:
24792479
jest-mock "^23.1.0"
24802480
jest-util "^23.1.0"
24812481

2482-
jest-environment-selenium@^1.0.0:
2483-
version "1.0.0"
2484-
resolved "https://registry.yarnpkg.com/jest-environment-selenium/-/jest-environment-selenium-1.0.0.tgz#e5361f2078ffdbfa2b07dde41bbc3f73b3c9b861"
2482+
jest-environment-selenium@^1.1.0:
2483+
version "1.1.0"
2484+
resolved "https://registry.yarnpkg.com/jest-environment-selenium/-/jest-environment-selenium-1.1.0.tgz#f1b6ee16f5f21e61c4918c5f81d80b9c039339ab"
24852485
dependencies:
24862486
jest-environment-node "^23.1.0"
24872487
selenium-webdriver "^3.6.0"

packages/selianize/__tests__/configuration.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ describe("configuration code emitter", () => {
2222
const project = {
2323
url: "http://www.seleniumhq.org"
2424
};
25-
return expect(ConfigurationEmitter.emit(project)).resolves.toBe(`global.BASE_URL = configuration.baseUrl || '${project.url}';const vars = {};`);
25+
return expect(ConfigurationEmitter.emit(project)).resolves.toBe(`global.BASE_URL = configuration.baseUrl || '${project.url}';let vars = {};`);
2626
});
2727
});

packages/selianize/__tests__/template.spec.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)