Skip to content

Commit

Permalink
chore: Add more selectors + remove PAT
Browse files Browse the repository at this point in the history
  • Loading branch information
maximgeerinck committed Apr 26, 2023
1 parent 2143afa commit 40b6743
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 52 deletions.
76 changes: 72 additions & 4 deletions commands/phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,23 @@ module.exports = {
}
return true;
},
getWalletAddress: async () => {
getWalletAddress: async (chain = 'eth') => {
await switchToPhantomIfNotActive();
await playwright.windows(PROVIDER).hover(mainPageElements.accountBar.title);
await new Promise(resolve => setTimeout(resolve, 100));
await playwright.waitAndClick(PROVIDER, mainPageElements.accountBar.ethRow);

if (chain === 'eth') {
await playwright.waitAndClick(
PROVIDER,
mainPageElements.accountBar.ethRow,
);
} else if (chain === 'solana') {
await playwright.waitAndClick(
PROVIDER,
mainPageElements.accountBar.solanaRow,
);
}

walletAddress = await playwright
.windows(PROVIDER)
.evaluate('navigator.clipboard.readText()');
Expand Down Expand Up @@ -418,6 +430,43 @@ module.exports = {
return true;
}
},
selectDefaultWallet: async wallet => {
if (!Object.keys(mainPageElements.defaultWallet).includes(wallet)) {
throw new Error(
'Wallet not supported, support ' +
Object.keys(mainPageElements.defaultWallet).join(', '),
);
}

await switchToPhantomIfNotActive();

// click settings
await playwright.waitAndClick(
PROVIDER,
mainPageElements.settingsMenu.settingsMenuButton,
);

// click gear in sidebar settings
await playwright.waitAndClick(
PROVIDER,
mainPageElements.settingsMenu.settingsSidebarButton,
);

// click default app wallet row
await playwright.waitAndClick(
PROVIDER,
mainPageElements.settingsMenu.defaultAppWalletRow,
);

// click option
await playwright.waitAndClick(
PROVIDER,
mainPageElements.defaultWallet[wallet],
);

// go back to main menu
await backToMainFromSettings();
},
disconnectWalletFromDapp: async () => {
await switchToPhantomIfNotActive();
await playwright.waitAndClick(
Expand All @@ -441,6 +490,7 @@ module.exports = {
.waitForSelector(mainPageElements.connectedSites.trustedAppsRevokeButton);
const hasRevokeButton = await revokeButtonLocator.isVisible();

let isDisconnected = false;
if (hasRevokeButton) {
console.log(
'[disconnectWalletFromDapp] Wallet is connected to a dapp, disconnecting...',
Expand All @@ -450,13 +500,17 @@ module.exports = {
mainPageElements.connectedSites.trustedAppsRevokeButton,
);
await switchToCypressIfNotActive();
return true;
isDisconnected = true;
} else {
console.log(
'[disconnectWalletFromDapp] Wallet is not connected to a dapp, skipping...',
);
}
return false;

// back to main
await backToMainFromSettings();

return isDisconnected;
},
};

Expand All @@ -476,3 +530,17 @@ async function switchToCypressIfNotActive() {
}
return switchBackToCypressWindow;
}

async function backToMainFromSettings() {
// click back
await playwright.waitAndClick(
PROVIDER,
mainPageElements.connectedSites.trustedAppsBackButton,
);

// click close menu
await playwright.waitAndClick(
PROVIDER,
mainPageElements.settingsMenu.settingsSidebarCloseButton,
);
}
103 changes: 56 additions & 47 deletions helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,53 +157,62 @@ module.exports = {
let tagName;
let response;

try {
if (version === 'latest' || !version) {
if (process.env.GH_USERNAME && process.env.GH_PAT) {
response = await axios.get(
'https://api.github.com/repos/phantom-labs/phantom-wallet/releases',
{
auth: {
username: process.env.GH_USERNAME,
password: process.env.GH_PAT,
},
},
);
} else {
response = await axios.get(
'https://api.github.com/repos/phantom-labs/phantom-wallet/releases',
);
}
filename = response.data[0].assets[0].name;
downloadUrl = response.data[0].assets[0].url;
tagName = 'phantom-chrome-latest';
log(
`Phantom version found! Filename: ${filename}; Download url: ${downloadUrl}; Tag name: ${tagName}`,
);
} else if (version) {
filename = `chrome-dist.zip`;
downloadUrl = `https://github.com/phantom-labs/phantom-wallet/releases/download/v${version}/chrome-dist.zip`;
tagName = `phantom-chrome-${version}`;
log(
`Phantom version found! Filename: ${filename}; Download url: ${downloadUrl}; Tag name: ${tagName}`,
);
}
return {
filename,
downloadUrl,
tagName,
};
} catch (e) {
if (e.response && e.response.status === 403) {
throw new Error(
`[getPhantomReleases] Unable to fetch phantom releases from GitHub because you've been rate limited! Please set GH_USERNAME and GH_PAT environment variables to avoid this issue or retry again.`,
);
} else {
throw new Error(
`[getPhantomReleases] Unable to fetch phantom releases from GitHub with following error:\n${e}`,
);
}
}
/**
* We don't have github releases public for now. Hardcode values until we have
*/
return {
filename: 'phantom-chrome-latest',
downloadUrl: 'chrome-dist.zip',
tagName: 'phantom-chrome-latest',
};
// try {
// if (version === 'latest' || !version) {
// if (process.env.GH_USERNAME && process.env.GH_PAT) {
// response = await axios.get(
// 'https://api.github.com/repos/phantom/wallet/releases',
// {
// auth: {
// username: process.env.GH_USERNAME,
// password: process.env.GH_PAT,
// },
// },
// );
// } else {
// response = await axios.get(
// 'https://api.github.com/repos/phantom/wallet/releases',
// );
// }
// console.log(response.data[0])
// filename = response.data[0].assets[0].name;
// downloadUrl = response.data[0].assets[0].url;
// tagName = 'phantom-chrome-latest';
// log(
// `Phantom version found! Filename: ${filename}; Download url: ${downloadUrl}; Tag name: ${tagName}`,
// );
// } else if (version) {
// filename = `chrome-dist.zip`;
// downloadUrl = `https://github.com/phantom-labs/wallet/releases/download/v${version}/chrome-dist.zip`;
// tagName = `phantom-chrome-${version}`;
// log(
// `Phantom version found! Filename: ${filename}; Download url: ${downloadUrl}; Tag name: ${tagName}`,
// );
// }
// return {
// filename,
// downloadUrl,
// tagName,
// };
// } catch (e) {
// if (e.response && e.response.status === 403) {
// throw new Error(
// `[getPhantomReleases] Unable to fetch phantom releases from GitHub because you've been rate limited! Please set GH_USERNAME and GH_PAT environment variables to avoid this issue or retry again.`,
// );
// } else {
// throw new Error(
// `[getPhantomReleases] Unable to fetch phantom releases from GitHub with following error:\n${e}`,
// );
// }
// }
},
download: async (provider, url, destination) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phantom/synpress",
"version": "4.0.0-alpha.8",
"version": "4.0.0-alpha.16",
"description": "Synpress is e2e testing framework based around Cypress.io & playwright with included MetaMask support. Test your dapps with ease.",
"keywords": [
"Synpress",
Expand Down
11 changes: 11 additions & 0 deletions pages/phantom/main-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ const accountMenu = {
const settingsMenu = {
settingsMenuButton: '[data-testid="settings-menu-open-button"]',
settingsSidebarButton: '[data-testid="sidebar_menu-button-settings"]',
settingsSidebarCloseButton: '[data-testid="settings-menu-close-button"]',
trustedAppsRow: '[data-testid="settings-item-trusted-apps"]',
defaultAppWalletRow: '[data-testid="settings-item-metamask-override"]',
};

const whatsNew = {
Expand All @@ -88,10 +90,18 @@ const welcome = {
const accountBar = {
title: '[data-testid="tooltip_interactive-wrapper"]',
ethRow: '[data-testid="account-header-chain-eip155:1"]',
solanaRow: '[data-testid="account-header-chain-solana:101"]',
};

const defaultWallet = {
metamask: '[data-testid="metamask-override--USE_METAMASK"]',
phantom: '[data-testid="metamask-override--USE_PHANTOM"]',
always_ask: '[data-testid="metamask-override--ALWAYS_ASK"]',
};

const connectedSites = {
trustedAppsRevokeButton: '[data-testid="trusted-apps-revoke-button"]',
trustedAppsBackButton: '[data-testid="header--back"]',
};

const accountModal = {
Expand Down Expand Up @@ -151,4 +161,5 @@ module.exports.mainPageElements = {
asset,
whatsNew,
welcome,
defaultWallet,
};

0 comments on commit 40b6743

Please sign in to comment.