Answered

Clearing the web browser cache from Subject7

I

have a test which is trying to clear the browser cache. Currently this is in Chrome, but eventually will want to do the same in Firefox and Edge.

The test executes a command which brings up the popup to clear the cache, but I need the test to press the clear button. While the browser inspect area will locate an XPath to the button, that button the XPath does not locate the clear button when I try a click operation. Also, the browser does not find clear button when the XPath is added to the find field. I am given to understand that his is because the Chrome settings page uses Polymer and WebComponents.

 

Upshot, is there a good way to clear the caches in the various browsers.

0
10 comments
Avatar
Joseph Hamdan

Hi William,

Could you please try taking a screenshot for the button, upload it, use it in a Sikuli locator and use this locator in Desktop_Click command?

I did a simple test and it worked. This post also shows some helpful info if you are using Desktop_Hotkey command to show Clear Cache window:
https://subject7.zendesk.com/hc/en-us/community/posts/360046787914-Desktop-Hotkeys-command-not-working-for-CTRL-SHIFT-DELETE-in-Chrome-Firefox-

Regards,
Subject7 Team

0
Comment actions Permalink
Avatar
William Smith

I know it has been a while, but I am finally getting some time to work on this.

I tried the Desktop_Click command with a Sikuli locator loaded with an image of the “Clear Data” button. That did not appear to work. Any ideas what I might be doing wrong?

 

In the Desktop_Click_Options locator I have selected "Use Locator".   The reference point contains the Sikuli Locator (chrome_clear_data) and offsets and extension values are left at the default of 0.   The Similarity value is also at the default of 0.70.

 

0
Comment actions Permalink
Avatar
William Smith

Hi Joseph:

I guess that didn't appear to really address the issue I was having.   The test does the CTRL+SHIFT+DELETE ok already and I get the popup up which asks me to confirm that I want to clear the data.   It is pressing the "Clear data" button which is the issue.    I am not having the issue addressed in the article which suggests that the CTRL+SHIFT+DELETE is not working.   It is.

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi William,

Thank you for responding and confirming. When it comes to the image, does any element get highlighted or the step with Desktop_Click fails with "Supporting element not found"? Can you capture the image one more time, go to Artifacts > File Uploads, re-upload the image that the Sikuli locator is using and try one more time?

When it comes to different browsers, there's a simple way to do it with conditions as below. Basically using the variable @system.browser will allow you to use different steps when the test case is launched on a specific browser.

1. When Chrome is launched, you can use Desktop_Hotkeys command with CTRL+SHIFT+DELETE and Desktop_Click to click Clear Data button.

2. When Firefox is launched, you can use Desktop_Hotkeys command with CTRL+SHIFT+DELETE and Desktop_Hotkeys with ENTER.

3. When Edge is launched, you can use Desktop_Hotkeys command with CTRL+SHIFT+DELETE and Desktop_Click to click Clear Now button.

Regards,
Subject7 Team

0
Comment actions Permalink
Avatar
William Smith

Thanks Joseph:

So, here is where I am at:
WIth regard to the items you listed, (1, 2, and 3) and @system_browser thanks, I was aware of those areas and planned to utilize that capability once I had this figured out.  Thanks for the reminder.

With regard to the locator, I did get it working, sort of.  

I am running on a windows PC with two screens.   I found that the locator works when I execute the execution screen displaying on one of my monitors but not the other.  Also, only if the image is extracted on that monitor.  Originally I had the image extracted on the other monitor, and the locator did not work on either monitor.

So, there is a solution which works, but I am not sure how satisfying it is. The results are non-portable to other testers with different monitor, and relies on my executing the test on a particular monitor.  Also, I notice when I am moving the mouse, the desktop locator cannot click on the item.  I have to not touch the mouse.

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi William,

One quick question, what is the operating system that is mostly used to run test cases? Is it Windows or MacOS ?

Regards,
Subject7 Team

0
Comment actions Permalink
Avatar
William Smith

Windows for my group.

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi William,

Here is a quick workaround. You can copy the snippet below, go to Advanced View icon, paste it and click Apply. I recommend creating a test with just these steps, try it out and if it works, make it a function and call it in your test case when required.

Commands Editor tab snippet:

WEB GOTO_URL "https://github.com/" HALT ON ERROR 
PRINT TEXT "Do some stuff" OUTPUT CONSOLE HALT ON ERROR
DESKTOP HOTKEYS CTRL,SHIFT,DELETE TARGET FOCUSED_ELEMENT HALT ON ERROR
IF @system.browser EQUAL "CHROME" AS TEXT
WEB SWITCH WINDOW BY POPUP "Settings" DURATION_TYPE WHOLE_TEST_CASE HALT ON ERROR
WEB EXECUTE SCRIPT "document.querySelector('settings-ui').shadowRoot\n .querySelector('settings-main').shadowRoot\n .querySelector('settings-basic-page').shadowRoot\n .querySelector('settings-privacy-page').shadowRoot\n .querySelector('settings-clear-browsing-data-dialog').shadowRoot\n .querySelector('cr-dialog[id=clearBrowsingDataDialog]')\n .querySelector('cr-button[id=clearBrowsingDataConfirm]')\n .click();" HALT ON ERROR
WEB SWITCH WINDOW BY MAIN DURATION_TYPE DEFAULT HALT ON ERROR
ELSE_IF @system.browser EQUAL "FIRE_FOX" AS TEXT
DESKTOP HOTKEYS ENTER TARGET FOCUSED_ELEMENT HALT ON ERROR
ELSE_IF @system.browser EQUAL "EDGE" AS TEXT
WEB SWITCH WINDOW BY POPUP "Settings" DURATION_TYPE WHOLE_TEST_CASE HALT ON ERROR
WEB EXECUTE SCRIPT "document.querySelector('button[id=\"clear-now\"]').click();" HALT ON ERROR
WEB SWITCH WINDOW BY MAIN DURATION_TYPE DEFAULT HALT ON ERROR
IF_END

Or JSON Editor tab snippet (Dashboard Preferences should have Compact view selected):

{"command":"GOTO_URL","args":{"url":"https://github.com/"}}
{"command":"PRINT","args":{"message":"Do some stuff","includeHeaders":true,"type":"MESSAGE","target":"CONSOLE"}}
{"command":"DESKTOP_HOTKEYS","args":{"componentType":"FOCUSED","hotKeys":["CTRL","SHIFT","DELETE"],"desktop_element":"<NOT SELECTED>","similarity":0.7}}
{"command":"IF","args":{"storeResult":false,"operator":"EQUAL","comparisonType":"TEXT","caseSensitive":false,"leftValue":"@system.browser","rightValue":"CHROME","threshold":0.1}}
{"command":"SWITCH_WINDOW","args":{"value":"Settings","switchType":"POPUP","switchDurationType":"WHOLE_TEST_CASE"}}
{"command":"EXECUTE_JAVASCRIPT","args":{"locators":[],"snippet":"document.querySelector('settings-ui').shadowRoot\n .querySelector('settings-main').shadowRoot\n .querySelector('settings-basic-page').shadowRoot\n .querySelector('settings-privacy-page').shadowRoot\n .querySelector('settings-clear-browsing-data-dialog').shadowRoot\n .querySelector('cr-dialog[id=clearBrowsingDataDialog]')\n .querySelector('cr-button[id=clearBrowsingDataConfirm]')\n .click();"}}
{"command":"SWITCH_WINDOW","args":{"switchType":"MAIN","switchDurationType":"DEFAULT"}}
{"command":"ELSE_IF","args":{"storeResult":false,"operator":"EQUAL","comparisonType":"TEXT","caseSensitive":false,"leftValue":"@system.browser","rightValue":"FIRE_FOX","threshold":0.1}}
{"command":"DESKTOP_HOTKEYS","args":{"componentType":"FOCUSED","hotKeys":["ENTER"],"desktop_element":"<NOT SELECTED>","similarity":0.7}}
{"command":"ELSE_IF","args":{"storeResult":false,"operator":"EQUAL","comparisonType":"TEXT","caseSensitive":false,"leftValue":"@system.browser","rightValue":"EDGE","threshold":0.1}}
{"command":"SWITCH_WINDOW","args":{"value":"Settings","switchType":"POPUP","switchDurationType":"WHOLE_TEST_CASE"}}
{"command":"EXECUTE_JAVASCRIPT","args":{"locators":[],"snippet":"document.querySelector('button[id=\"clear-now\"]').click();"}}
{"command":"SWITCH_WINDOW","args":{"switchType":"MAIN","switchDurationType":"DEFAULT"}}
{"command":"END_IF","args":{}}

However, Selenium4 has a much better way to handle this, we are still waiting for a more stable release of it and then we will just provide commands to handle similar things using Selenium4.

Regards,
Subject7 Team

0
Comment actions Permalink
Avatar
William Smith

Thanks.  I used the Commands Editor snippet and it worked well enough.   With regard to the desktop hotkeys mentioned earlier, that works as well.   I did leave a comment in that conversation about how adding a NUM_LOCK change into the test causes it to change state each time I execute the test.   I think I have some coding workarounds I can try, but it won't be clean.   The above code is useful to me even without the workarounds.   Thanks.

0
Comment actions Permalink

Please sign in to leave a comment.