Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "clearSession" browser command #824

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

DudaGod
Copy link
Member

@DudaGod DudaGod commented Dec 29, 2023

No description provided.

@@ -385,6 +385,30 @@ Finally, run tests (be sure that you have already run `selenium-standalone start
node_modules/.bin/hermione
```

## Commands API

Since Hermione is based on [WebdriverIO v8](https://webdriver.io/docs/api/), all the commands provided by WebdriverIO are available in it. But Hermione also has her own commands.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Взял из нашей внутренней доки. Вообще нужно бы отдельную страницу завести. Ну и странно что у нас до этого не было отдельного раздела с командами.

export = async (browser: Browser): Promise<void> => {
const { publicAPI: session } = browser;

const clearStorage = async (storageName: "localStorage" | "sessionStorage"): Promise<void> => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хелпер для очестки стореджей

} catch (e) {
const message = (e as Error).message || "";

if (message.startsWith(`Failed to read the '${storageName}' property from 'Window'`)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Обращение к localStorage и sessionStorage на странице about:blank, data:, и скорей всего прочих системных не работает. Поэтому в этом случае просто матчусь на команду и кидаю варнинг с ошибкой.

const message = (e as Error).message || "";

if (message.startsWith(`Failed to read the '${storageName}' property from 'Window'`)) {
logger.log(`Couldn't clear ${storageName}: ${message}`);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь message юзаю, так как в стеке ничего интересного вообще нет, так как команда выполняется в браузере.

const clearStorage = async (storageName: "localStorage" | "sessionStorage"): Promise<void> => {
try {
await session.execute(storageName => window[storageName].clear(), storageName);
} catch (e) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кетчить можно было бы внутри execute, но тогда ошибка бы падала в консоль браузера. Поэтому оборачиваю весь execute

await session.deleteAllCookies();

await clearStorage("localStorage");
await clearStorage("sessionStorage");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не придумал что тут можно еще почистить.

@DudaGod DudaGod force-pushed the HERMIONE-1313.clear_session_cmd branch 2 times, most recently from e26a1bb to 4f8dc42 Compare December 29, 2023 14:54
Copy link
Member

@KuznetsovRoman KuznetsovRoman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Там ci ругается. В остальном /ok

README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@DudaGod DudaGod force-pushed the HERMIONE-1313.clear_session_cmd branch from 4f8dc42 to 7114cd5 Compare January 10, 2024 14:19
@DudaGod DudaGod closed this Jan 11, 2024
@DudaGod DudaGod force-pushed the HERMIONE-1313.clear_session_cmd branch from f09fc5f to 496fae9 Compare January 11, 2024 12:22
@DudaGod DudaGod reopened this Jan 11, 2024
@DudaGod DudaGod merged commit 53a7faa into master Jan 11, 2024
6 checks passed
@DudaGod DudaGod deleted the HERMIONE-1313.clear_session_cmd branch January 11, 2024 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants