Get notified when execution context is changed or created - selenium

I am injecting bunch of javascript code to a website by means of selenium webdriver (over chromedriver).
While the method i use works most of the time, it fails when an iframe is loaded or page is reloaded by website's javascript code.
I can trace the problem from the chromedriver's log.
For example:
[6.203][DEBUG]: DEVTOOLS EVENT Runtime.executionContextDestroyed {
"executionContextId": 1
}
[6.203][DEBUG]: DEVTOOLS EVENT Runtime.executionContextsCleared {
}
[6.203][DEBUG]: DEVTOOLS EVENT Runtime.executionContextCreated {
"context": {
"auxData": {
"frameId": "274.1",
"isDefault": true
},
"id": 5,
"name": "",
"origin": "https://<some url>"
}
}
When i see executionContextDestroyed i know that, most probably my injected scripts are destroyed too. I have tried bunch of options like switch_to.default_content() or switch_to.parent_frame but they didn't help, as there is nothing to do in case of reload but re-inject the scripts.
My question is, is there a way to hook into executionContextCreated events, so i can inject my scripts/functions into the context again and again.

Related

strange behaviour Laravel Livewire with 2 instances

I have a simple page in Laravel 8 with livewire (jetstream). On that page i can open a modal form. In fact i have 2 modal forms in that page, one for editing and one for confirming prior to a delete.
I was testing and had Edge open with one instance (logged in a test user) and one instance in Chrome (logged in as another user).
When i opened the edit-modal on Chrome, the confirm-delete modal opened in my Edge browser.
I display my ConfirmDelete model with this:
<x-jet-dialog-modal wire:model="confirmDelete">
...
i watched my variable and it did go from false to true when i opende the other modal on my other browser.
{{-- modal form --}}
<x-jet-dialog-modal wire:model="modalFormVisible">
When i look at my Network tab in the Chrome diagnostics is see this:
{
"data": {
"modalFormVisible": true
},
"checksum": "7697e888b4472a9519f206d733a5d15e42a3f346b0d7fbcd349a25f67de67c86"
}
And at that same time, doing nothing in my edge browser, there i see this in my network tab:
{
"htmlHash": "f65525e2",
"data": {
"confirmDelete": true,
"modelId": null,
"name": null,
"myPermissions": null
},
"checksum": "60117ff32a9956f915e1a2dab4a6671ce2ff236435ae10c4955f94cb7f9d590d"
}
I am using Apache and am using browsersync.
Any Ideas? Is this normal behaviour?

Unable to click intercepted element in wdio 7

I'm using wdio 7 last couple of weeks. but still unable to resolve intercepted element.
In protractor, I'm using
browser.actions().
click($(".pay-modal-container i[class='webfont-date_range']")).
sendKeys(protractor.Key.TAB).
sendKeys(protractor.Key.TAB).
sendKeys(protractor.Key.ENTER).
perform();
Don't know In Wdio how it works. Please help me if anyone has an idea of it.
Note : Already used browser.execute("arguments[0].click()", locator); not doing anything if i used into script
The ElementClickInterceptedException occurs when a pop-up gets in the way of a regular Selenium/WebDriver click, (eg: How do I close pop-up windows with Selenium in Python when I don't know when they will pop up?)
When that happens, you have two options:
First click to close the pop-up that's in the way.
Use a Javascript click instead of a regular click.
Given that WDIO is already a Javascript framework, you should have no troubles running a Javascript command to perform that click. Or you may decide to click to close the pop-up first.
browser.performActions([{
"type": "pointer",
"id": "click on add button",
parameters: { pointerType: 'mouse' },
actions: [
{ type: 'pointerMove', x: 1, y: 1, origin: browser.findElement("css selector", locator) },
{ type: 'pointerDown', button: 0 },
{ type: 'pointerUp', button: 0 },
]
}
]);

BigCommerce Stencil Custom Page template not appearing

In Page Builder I've added a page called About Us which has the url '/about-us/'
I've been following the instructions found here
https://developer.bigcommerce.com/stencil-docs/storefront-customization/custom-templates
in order to make a custom template for that page.
I made a file called about-us.html in templates/pages/custom/page with the contents:
<h1>About Us Page Test</h1>
My .stencil file looks like the following
{
"normalStoreUrl": "my url",
"accessToken": "my access token",
"port": "3003",
"customLayouts": {
"brand": {},
"category": {},
"page": {
"about-us.html": "/about-us/"
},
"product": {}
}
}
I've stopped and reran 'stencil start' but every time I visit localhost:3003/about-us/ it just shows the normal page instead of the custom template I build.
Is there something I'm missing? Is this an issue with using the page builder in combination with stencil?
I assume you haven't set the custom template for your page yet.
Go to Web Pages and edit your About Us page then look for the Template Layout File dropdown. Your custom template should appear there if it is setup correctly.
The issue was resolved when a full system reboot was performed. I'm not sure why stopping and restarting stencil did not resolve this.

How to set proxy through setting.json in JetBrains Toolbox?

When I click change proxy setting button on this app, it will crash. And I realize that I can set proxy through settings.json. But in this file it shows like below.
{
"autostart": true,
"install_location": "D:/Jetbrains/ToolBox",
"privacy_policy": {
"eua_accepted_version": "1.1"
},
"proxy": null
"shell_scripts": {
"enabled": false
},
"statistics": {
"allow": true
},
"update": {
"filter": {
"quality_filter": {
"order_value": 10000
}
}
}
}
I got no idea about proxy:null, there is no sample to help me figure out how to set proxy through json. So what's the right properties about proxy in this file? Could anybody give a sample?
It takes a dictionary where the keys are the same variable names you'd define in your shell and the values are the values you'd assign them. For instance http_proxy, https_proxy, no_proxy. Here is an example of what I have in my settings.json:
"proxy": {
"http_proxy": "http://my.proxy.url:8888",
"https_proxy": "http://my.proxy.url:8888",
"no_proxy": "localhost,127.0.0.1,localaddress,.localdomain.com"
},
I also tried manually editing the .desktop file's Exec line by adding the proxy environmental variables and while that works the first launch, the .desktop file is overwritten each time the application is launched so it won't work on subsequent launches and won't work if you have the application launch on login. Setting the proxy in the settings.json is the only way to make it work without manual intervention every time it's launched.
This is not documented anywhere that I could find and I wasted way more time than I'd liek to admit before I tried this solution. I'm glad it was as simple as it is but how hard would that be to document? It may seem intuitive, but how often have we all been burned by something where the intuitive and logical answer was not the actual implementation.

How can i use the port.postmessage to send info from the background page to the content script in a Google Chrome extension

I've been able to send data from the background page to the content script. but this is done using sendrequest(). I will need to send data back and forth so I'm trying to figure out the correct syntax for using the port.postmessage from background page to content script. I have already read, several times, the google page on Messaging and I don't seem to get it. I even copied the code directly from the page and tested with no result. All I'm trying to do for now is send data from background page to content script using connect as opposed to sendrequest. The response from the content script I will deal with later as code with this response has been the main thorn. I just want to understand the process one step at a time without the extra knowledge of sending a response back.
I'm not sure if this contravenes the rules of this board but can someone PLEASE give me an example of some code to do this (background page and content script excerpt, the background page is the sender).
I've asked for assistance several times on this site only to be told to read the documentation or check out sites I've already visited.
If you just want any example of opening a port from the extension to a content script, here's the simplest I can think of. The background just opens a port and sends "Hello tab!" over the port, and the content script sends a message to the background any time you click on the webpage.
I think this is pretty simple, so I don't know why you are so stressed. Just make sure that the content tab is already listening when the background tries to connect (I do this by waiting until the "complete" event).
manifest.json:
{
"name": "TestExt",
"version": "0.1",
"background_page": "background.html",
"content_scripts": [{
"matches": ["http://localhost/*"], // same as background.html regexp
"js": ["injected.js"]
}],
"permissions": [
"tabs" // ability to inject js and listen to onUpdated
]
}
background.html:
<script>
var interestingTabs = {};
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
// same as manifest.json wildcard
if (changeInfo.url && /http:\/\/localhost(:\d+)?\/(.|$)/.test(changeInfo.url)) {
interestingTabs[tabId] = true;
}
if (changeInfo.status === 'complete' && interestingTabs[tabId]) {
delete interestingTabs[tabId];
console.log('Trying to connect to tab ' + tabId);
var port = chrome.tabs.connect(tabId);
port.onMessage.addListener(function(m) {
console.log('received message from tab ' + tabId + ':');
console.log(m);
});
port.postMessage('Hello tab!');
}
});
</script>
injection.js:
chrome.extension.onConnect.addListener(function(port) {
console.log('Connected to content script!');
port.onMessage.addListener(function(m) {
console.log('Received message:');
console.log(m);
});
document.documentElement.addEventListener('click', function(e) {
port.postMessage('User clicked on a ' + e.target.tagName);
}, true);
});
Detailed documentation and easy (the most basic) examples shown in the documentation page.
Plus, a quick search in stackoverflow will allow you to see many similar questions with detailed answers.