setValueWrapper refactor, fix process killing on macOs, remove unneeded resolves

pull/1044/head
Ryan Tharp 5 years ago
parent f5f9614680
commit 3d93c05929

@ -50,6 +50,38 @@ module.exports = {
return new Promise(resolve => setTimeout(resolve, ms));
},
// a wrapper to work around electron/spectron bug
async setValueWrapper(app, selector, value) {
await app.client.element(selector).click();
// keys, setValue and addValue hang on certain platforms
// could put a branch here to use one of those
// if we know what platforms are good and which ones are broken
await app.client.execute(
(slctr, val) => {
// eslint-disable-next-line no-undef
const iter = document.evaluate(
slctr,
// eslint-disable-next-line no-undef
document,
null,
// eslint-disable-next-line no-undef
XPathResult.UNORDERED_NODE_ITERATOR_TYPE,
null
);
const elem = iter.iterateNext();
if (elem) {
elem.value = val;
} else {
console.error('Cant find', slctr, elem, iter);
}
},
selector,
value
);
// let session js detect the text change
await app.client.element(selector).click();
},
async startApp(environment = 'test-integration-session') {
const env = environment.startsWith('test-integration')
? 'test-integration'
@ -92,16 +124,16 @@ module.exports = {
async stopApp(app1) {
if (app1 && app1.isRunning()) {
await app1.stop();
return Promise.resolve();
}
return Promise.resolve();
},
async killallElectron() {
// rtharp - my 2nd client on MacOs needs: pkill -f "node_modules/.bin/electron"
// node_modules/electron/dist/electron is node_modules/electron/dist/Electron.app on MacOS
const killStr =
process.platform === 'win32'
? 'taskkill /im electron.exe /t /f'
: 'pkill -f "node_modules/electron/dist/electron"';
: 'pkill -f "node_modules/electron/dist/electron" | pkill -f "node_modules/.bin/electron"';
return new Promise(resolve => {
exec(killStr, (err, stdout, stderr) => {
if (err) {
@ -145,23 +177,24 @@ module.exports = {
stubOpenGroups = false,
env = 'test-integration-session',
}) {
const app1 = await this.startAndAssureCleanedApp(env);
const app = await this.startAndAssureCleanedApp(env);
if (stubSnode) {
await this.startStubSnodeServer();
this.stubSnodeCalls(app1);
this.stubSnodeCalls(app);
}
if (stubOpenGroups) {
this.stubOpenGroupsCalls(app1);
this.stubOpenGroupsCalls(app);
}
if (mnemonic && displayName) {
await this.restoreFromMnemonic(app1, mnemonic, displayName);
await this.restoreFromMnemonic(app, mnemonic, displayName);
// not sure we need this - rtharp.
await this.timeout(2000);
}
return app1;
return app;
},
async startAndStub2(props) {
@ -173,18 +206,23 @@ module.exports = {
return app2;
},
async restoreFromMnemonic(app1, mnemonic, displayName) {
await app1.client.element(RegistrationPage.registrationTabSignIn).click();
await app1.client.element(RegistrationPage.restoreFromSeedMode).click();
await app1.client
.element(RegistrationPage.recoveryPhraseInput)
.setValue(mnemonic);
await app1.client
.element(RegistrationPage.displayNameInput)
.setValue(displayName);
await app1.client.element(RegistrationPage.continueSessionButton).click();
await app1.client.waitForExist(
async restoreFromMnemonic(app, mnemonic, displayName) {
await app.client.element(RegistrationPage.registrationTabSignIn).click();
await app.client.element(RegistrationPage.restoreFromSeedMode).click();
await this.setValueWrapper(
app,
RegistrationPage.recoveryPhraseInput,
mnemonic
);
await this.setValueWrapper(
app,
RegistrationPage.displayNameInput,
displayName
);
await app.client.element(RegistrationPage.continueSessionButton).click();
await app.client.waitForExist(
RegistrationPage.conversationListContainer,
4000
);
@ -214,9 +252,11 @@ module.exports = {
await app1.client.element(ConversationPage.contactsButtonSection).click();
await app1.client.element(ConversationPage.addContactButton).click();
await app1.client
.element(ConversationPage.sessionIDInput)
.setValue(this.TEST_PUBKEY2);
await this.setValueWrapper(
app1,
ConversationPage.sessionIDInput,
this.TEST_PUBKEY2
);
await app1.client.element(ConversationPage.nextButton).click();
await app1.client.waitForExist(
ConversationPage.sendFriendRequestTextarea,
@ -224,9 +264,11 @@ module.exports = {
);
// send a text message to that user (will be a friend request)
await app1.client
.element(ConversationPage.sendFriendRequestTextarea)
.setValue(textMessage);
await this.setValueWrapper(
app1,
ConversationPage.sendFriendRequestTextarea,
textMessage
);
await app1.client.keys('Enter');
await app1.client.waitForExist(
ConversationPage.existingFriendRequestText(textMessage),
@ -284,9 +326,12 @@ module.exports = {
// next trigger the link request from the app2 with the app1 pubkey
await app2.client.element(RegistrationPage.registrationTabSignIn).click();
await app2.client.element(RegistrationPage.linkDeviceMode).click();
await app2.client
.element(RegistrationPage.textareaLinkDevicePubkey)
.setValue(this.TEST_PUBKEY1);
await this.setValueWrapper(
app2,
RegistrationPage.textareaLinkDevicePubkey,
this.TEST_PUBKEY1
);
await app2.client.element(RegistrationPage.linkDeviceTriggerButton).click();
await app1.client.waitForExist(RegistrationPage.toastWrapper, 7000);
let secretWordsapp1 = await app1.client

Loading…
Cancel
Save