-
Notifications
You must be signed in to change notification settings - Fork 64
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
Conversation
@@ -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. |
There was a problem hiding this comment.
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> => { |
There was a problem hiding this comment.
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'`)) { |
There was a problem hiding this comment.
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:,
и скорей всего прочих системных не работает. Поэтому в этом случае просто матчусь на команду и кидаю варнинг с ошибкой.
src/browser/commands/clearSession.ts
Outdated
const message = (e as Error).message || ""; | ||
|
||
if (message.startsWith(`Failed to read the '${storageName}' property from 'Window'`)) { | ||
logger.log(`Couldn't clear ${storageName}: ${message}`); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не придумал что тут можно еще почистить.
e26a1bb
to
4f8dc42
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Там ci ругается. В остальном /ok
4f8dc42
to
7114cd5
Compare
f09fc5f
to
496fae9
Compare
No description provided.