2021-06-06 22:01:37 +08:00
|
|
|
const Page = require('../core/page');
|
|
|
|
const { exec } = require("child_process");
|
|
|
|
const { CLIENT_RECONNECTION_TIMEOUT } = require('../core/constants'); // core constants (Timeouts vars imported)
|
|
|
|
const { sleep } = require('../core/helper');
|
2021-08-21 04:33:57 +08:00
|
|
|
const e = require('../core/elements');
|
|
|
|
const { checkElementLengthDifferentTo } = require('../core/util');
|
2021-06-06 22:01:37 +08:00
|
|
|
|
|
|
|
class Trigger extends Page {
|
|
|
|
constructor() {
|
2021-09-23 03:22:47 +08:00
|
|
|
super();
|
2021-06-06 22:01:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async triggerMeteorDisconnect(testName) {
|
2021-08-14 01:35:00 +08:00
|
|
|
try {
|
2021-08-14 04:33:27 +08:00
|
|
|
await this.screenshot(`${testName}`, `01-before-audio-modal-close-[${this.meetingId}]`);
|
|
|
|
|
2021-08-14 01:35:00 +08:00
|
|
|
await this.closeAudioModal();
|
2021-08-14 04:33:27 +08:00
|
|
|
await this.screenshot(`${testName}`, `02-after-audio-modal-close-[${this.meetingId}]`);
|
|
|
|
|
2021-08-14 01:35:00 +08:00
|
|
|
await sleep(5000);
|
|
|
|
await this.page.evaluate(() => Meteor.disconnect());
|
2021-08-14 04:33:27 +08:00
|
|
|
await this.screenshot(`${testName}`, `03-after-meteor-disconnection-[${this.meetingId}]`);
|
|
|
|
|
2021-08-14 01:35:00 +08:00
|
|
|
await sleep(CLIENT_RECONNECTION_TIMEOUT);
|
|
|
|
const meteorStatus = await this.page.evaluate(() => Meteor.status());
|
|
|
|
const meteorStatusConfirm = await meteorStatus.status === "offline";
|
|
|
|
await this.logger('Check if Meteor is Offline => ', meteorStatusConfirm);
|
2021-09-22 11:51:29 +08:00
|
|
|
const getAudioButton = await this.page.evaluate((joinAudioSelector) => {
|
|
|
|
return document.querySelectorAll(joinAudioSelector)[0].getAttribute('aria-disabled') === "true";
|
|
|
|
}, e.joinAudio);
|
2021-08-14 01:35:00 +08:00
|
|
|
await this.logger('Check if Connections Buttons are disabled => ', getAudioButton);
|
|
|
|
await this.page.evaluate(() => Meteor.reconnect());
|
|
|
|
await sleep(3000);
|
2021-08-14 04:33:27 +08:00
|
|
|
await this.screenshot(`${testName}`, `04-after-meteor-reconnection-[${this.meetingId}]`);
|
|
|
|
|
2021-09-03 02:31:24 +08:00
|
|
|
const findUnauthorized = await this.page.evaluate(checkElementLengthDifferentTo, e.unauthorized, 0) === true;
|
2021-08-14 01:35:00 +08:00
|
|
|
await this.logger('Check if Unauthorized message appears => ', findUnauthorized);
|
|
|
|
return meteorStatusConfirm && getAudioButton && findUnauthorized;
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
await this.logger(err);
|
2021-08-14 01:35:00 +08:00
|
|
|
return false;
|
2021-06-06 22:01:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async triggerNetworkServiceDisconnection(testName) {
|
2021-08-14 01:35:00 +08:00
|
|
|
try {
|
2021-08-14 04:33:27 +08:00
|
|
|
await this.screenshot(`${testName}`, `01-before-audio-modal-close-[${this.meetingId}]`);
|
|
|
|
|
2021-08-14 01:35:00 +08:00
|
|
|
await this.closeAudioModal();
|
2021-08-14 04:33:27 +08:00
|
|
|
await this.screenshot(`${testName}`, `02-after-audio-modal-close-[${this.meetingId}]`);
|
|
|
|
|
2021-08-14 01:35:00 +08:00
|
|
|
await sleep(5000);
|
|
|
|
await this.logger('Stopping Network Service...');
|
2021-08-14 05:43:59 +08:00
|
|
|
await exec('sh events/stop-network.sh', async (error, data, getter) => {
|
2021-08-14 01:35:00 +08:00
|
|
|
if (error) {
|
2021-08-14 05:43:59 +08:00
|
|
|
await this.logger("error", error.message);
|
2021-08-14 01:35:00 +08:00
|
|
|
return;
|
2021-06-06 22:01:37 +08:00
|
|
|
}
|
2021-08-14 01:35:00 +08:00
|
|
|
if (getter) {
|
2021-08-14 05:43:59 +08:00
|
|
|
await this.logger("data", data);
|
2021-08-14 01:35:00 +08:00
|
|
|
return;
|
2021-06-06 22:01:37 +08:00
|
|
|
}
|
2021-08-14 05:43:59 +08:00
|
|
|
await this.logger("data", data);
|
2021-08-14 01:35:00 +08:00
|
|
|
});
|
|
|
|
const meteorStatus = await this.page.evaluate(() => Meteor.status());
|
|
|
|
const meteorStatusConfirm = await meteorStatus.status === "offline";
|
|
|
|
await this.logger('Check if Meteor is Offline => ', meteorStatusConfirm);
|
2021-08-14 04:33:27 +08:00
|
|
|
await this.screenshot(`${testName}`, `03-after-network-service-shutdown-[${this.meetingId}]`);
|
|
|
|
|
2021-08-14 01:35:00 +08:00
|
|
|
await this.logger('Counting ', CLIENT_RECONNECTION_TIMEOUT / 6000, ' seconds...');
|
|
|
|
await sleep(CLIENT_RECONNECTION_TIMEOUT);
|
|
|
|
await this.logger('Restarting Network Service...');
|
2021-08-14 05:43:59 +08:00
|
|
|
await exec('sh events/restart-network.sh', async (error, data, getter) => {
|
2021-08-14 01:35:00 +08:00
|
|
|
if (error) {
|
2021-08-14 05:43:59 +08:00
|
|
|
await this.logger("error", error.message);
|
2021-08-14 01:35:00 +08:00
|
|
|
return;
|
2021-06-06 22:01:37 +08:00
|
|
|
}
|
2021-08-14 01:35:00 +08:00
|
|
|
if (getter) {
|
2021-08-14 05:43:59 +08:00
|
|
|
await this.logger("data", data);
|
2021-08-14 01:35:00 +08:00
|
|
|
return;
|
2021-06-06 22:01:37 +08:00
|
|
|
}
|
2021-08-14 05:43:59 +08:00
|
|
|
await this.logger("data", data);
|
2021-08-14 01:35:00 +08:00
|
|
|
});
|
2021-08-14 04:33:27 +08:00
|
|
|
await this.screenshot(`${testName}`, `04-after-network-service-restart-[${this.meetingId}]`);
|
|
|
|
|
2021-08-14 01:35:00 +08:00
|
|
|
await this.page.reload();
|
|
|
|
await this.closeAudioModal();
|
2021-09-03 02:31:24 +08:00
|
|
|
const getAudioButton = await this.page.evaluate((joinAudioSelector) => {
|
|
|
|
return document.querySelectorAll(joinAudioSelector)[0].getAttribute('aria-disabled') === "true";
|
|
|
|
}, e.joinAudio)
|
2021-08-14 01:35:00 +08:00
|
|
|
await this.logger('Check if Connections Buttons are disabled => ', getAudioButton);
|
|
|
|
await sleep(3000);
|
2021-09-03 02:31:24 +08:00
|
|
|
const findUnauthorized = await this.page.evaluate(checkElementLengthDifferentTo, e.unauthorized, 0) === true;
|
2021-08-14 01:35:00 +08:00
|
|
|
await this.logger('Check if Unauthorized message appears => ', findUnauthorized);
|
|
|
|
return meteorStatusConfirm && getAudioButton && findUnauthorized;
|
2021-08-26 22:13:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
await this.logger(err);
|
2021-08-14 01:35:00 +08:00
|
|
|
return false;
|
2021-06-06 22:01:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = Trigger;
|