Skip to content

Commit

Permalink
Merge pull request #652 from amtrack/refactor/handle-web-cmps-without…
Browse files Browse the repository at this point in the history
…-shadow-root

refactor: handle web components without shadow root
  • Loading branch information
amtrack authored Dec 6, 2024
2 parents 8cf0699 + a303550 commit 0fc85e0
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/browserforce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LoginPage } from './pages/login.js';

const ERROR_DIV_SELECTOR = '#errorTitle';
const ERROR_DIVS_SELECTOR = 'div.errorMsg';
const VF_IFRAME_SELECTOR = 'iframe[name^=vfFrameId]';
const VF_IFRAME_SELECTOR = 'force-aloha-page iframe[name^=vfFrameId]';

export class Browserforce {
public org: Org;
Expand Down Expand Up @@ -99,8 +99,8 @@ export class Browserforce {
// Wait for either the selector in the page or in the iframe.
// returns the page or the frame
public async waitForSelectorInFrameOrPage(page: Page, selector: string): Promise<Page | Frame> {
await page.waitForSelector(`pierce/${VF_IFRAME_SELECTOR}, ${selector}`);
const frameElementHandle = await page.$(`pierce/${VF_IFRAME_SELECTOR}`);
await page.waitForSelector(`${selector}, ${VF_IFRAME_SELECTOR}`);
const frameElementHandle = await page.$(VF_IFRAME_SELECTOR);
let frameOrPage: Page | Frame = page;
if (frameElementHandle) {
const frame = await page.waitForFrame(
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/density-settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const PATHS = {
};

const SELECTORS = {
PICKER_ITEMS: 'pierce/one-density-visual-picker one-density-visual-picker-item input'
PICKER_ITEMS: 'one-density-visual-picker one-density-visual-picker-item input'
};

type Config = {
Expand Down
8 changes: 3 additions & 5 deletions src/plugins/high-velocity-sales-settings/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { throwPageErrors } from '../../browserforce.js';

const SET_UP_AND_ENABLE_HVS_BUTTON = 'button.setupAndEnableButton';
const ENABLE_TOGGLE = '#toggleHighVelocitySalesPref';
const AUTOMATION_TAB_ITEM = 'pierce/#automationTab__item';
const AUTOMATION_TAB_ITEM = 'lightning-tab-bar li[data-tab-value="automationTab"]';

export class HighVelocitySalesSetupPage {
private page: Page;
Expand All @@ -17,14 +17,12 @@ export class HighVelocitySalesSetupPage {
}

public async setUpAndEnable(): Promise<void> {
// starting Winter 24 (v59.0) there is a new tab bar and the item is located in the "Automation" tab
// wait for tab item or the button directly
await this.page.waitForSelector(`${AUTOMATION_TAB_ITEM}, ${SET_UP_AND_ENABLE_HVS_BUTTON}`, { timeout: 60_000 });
await this.page.waitForSelector(AUTOMATION_TAB_ITEM);
const tab = await this.page.$(AUTOMATION_TAB_ITEM);
if (tab) {
await this.page.evaluate((e: HTMLElement) => e.click(), tab);
}
await this.page.waitForSelector(SET_UP_AND_ENABLE_HVS_BUTTON, { timeout: 60_000 });
await this.page.waitForSelector(SET_UP_AND_ENABLE_HVS_BUTTON);
const enableButton = await this.page.$(SET_UP_AND_ENABLE_HVS_BUTTON);
await Promise.all([
this.page.waitForSelector(ENABLE_TOGGLE, { timeout: 60_000 }),
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/lightning-experience-settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const PATHS = {
BASE: 'lightning/setup/ThemingAndBranding/home'
};

const THEME_ROW_SELECTOR = 'pierce/#setupComponent lightning-datatable table > tbody > tr';
const THEME_ROW_SELECTOR = '#setupComponent lightning-datatable table > tbody > tr';
const SELECTORS = {
DEVELOPER_NAMES: `${THEME_ROW_SELECTOR} > td:nth-child(2) > lightning-primitive-cell-factory lightning-base-formatted-text`,
STATES: `${THEME_ROW_SELECTOR} > td:nth-child(6) > lightning-primitive-cell-factory`
Expand Down Expand Up @@ -71,13 +71,13 @@ export class LightningExperienceSettings extends BrowserforcePlugin {
visible: true
});
const menuButton = await newActiveThemeRowElementHandle.$(
'pierce/td lightning-primitive-cell-factory lightning-primitive-cell-actions lightning-button-menu'
'td lightning-primitive-cell-factory lightning-primitive-cell-actions lightning-button-menu'
);
await page.evaluate((e: HTMLElement) => e.click(), menuButton);
await page.waitForSelector(`${THEME_ROW_SELECTOR} lightning-button-menu slot lightning-menu-item`, {
visible: true
});
const menuItems = await menuButton!.$$('pierce/slot lightning-menu-item');
const menuItems = await menuButton!.$$('slot lightning-menu-item');
// second last item: [show, activate, preview]
const activateMenuItem = menuItems[menuItems.length - 2];
await Promise.all([page.waitForNavigation(), page.evaluate((e: HTMLElement) => e.click(), activateMenuItem)]);
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/linkedin-sales-navigator-settings/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { throwPageErrors } from '../../browserforce.js';

const ENABLE_TOGGLE = 'div[data-aura-class="setup_sales_linkedinLinkedInSetupRow"] input[type="checkbox"]';
const CONFIRM_CHECKBOX =
'pierce/lightning-primitive-input-checkbox input[name="LinkedIn Sales Navigator Integration Acceptance Checkbox"]';
'lightning-input lightning-primitive-input-checkbox input[name="LinkedIn Sales Navigator Integration Acceptance Checkbox"]';
const ACCEPT_BUTTON =
'section[data-aura-class="setup_sales_linkedinLinkedInSetupAcceptTermsModal"] div div button:not(:disabled):nth-child(2)';

Expand All @@ -27,7 +27,8 @@ export class LinkedInSalesNavigatorPage {

public async setStatus(enable: boolean): Promise<void> {
await this.page.waitForSelector(ENABLE_TOGGLE, { visible: true });
await this.page.click(ENABLE_TOGGLE);
const toggle = await this.page.$(ENABLE_TOGGLE);
await toggle?.evaluate((input: HTMLInputElement) => input.click());

if (enable) {
await this.page.waitForSelector(CONFIRM_CHECKBOX, { visible: true });
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/slack/index.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ describe(Slack.name, function () {
agreeToTermsAndConditions: false,
enableSalesCloudForSlack: false
};
it('should accept terms and conditions', async () => {
it('should accept terms and conditions and enable Sales Cloud for Slack', async () => {
await plugin.run(configEnable);
});
it('should already be accepted', async () => {
it('should already be accepted and enabled', async () => {
const res = await plugin.run(configEnable);
assert.deepStrictEqual(res, { message: 'no action necessary' });
});
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/slack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const PATHS = {
};
const SELECTORS = {
TOS_LIGHTNING_INPUT:
'pierce/setup_service-slack-setup-assistant-container setup_service-slack-agree-to-terms lightning-input',
'setup_service-slack-setup-assistant-container setup_service-slack-agree-to-terms lightning-input',
SALES_CLOUD_FOR_SLACK_TOGGLE:
'pierce/setup_service-slack-setup-assistant-container setup_service-stage setup_service-steps setup_service-step lightning-input:has(lightning-primitive-input-toggle input[name="SlkSetupStepSalesCloudForSlack"])',
'setup_service-slack-setup-assistant-container setup_service-stage setup_service-steps setup_service-step lightning-input:has(lightning-primitive-input-toggle input[name="SlkSetupStepSalesCloudForSlack"])',
TOAST_MESSAGE: 'div[id^="toastDescription"]'
};

Expand Down

0 comments on commit 0fc85e0

Please sign in to comment.