could someone post example code for creating two browser instances and switching between those using Robot Framework's Browser (NOT using SeleniumLibrary) library?
Namely: how to obtain correct browser id for Switch Browser keyword.
Switch Browser ${browser_id}
Full code so far:
Library Browser
Library String
Library Collections
** Variables **
${url1}= https://www.google.com
${url1}= https://www.bing.com
#{browser_ids}= Create List
** Test Cases **
Open Browser 1
[Tags] UI dev
New Browser chromium headless=false
New Context viewport={'width': 1920, 'height': 1080}
New Page ${url1}
Open Browser 2
[Tags] UI dev
New Browser chromium headless=false
New Context viewport={'width': 1920, 'height': 1080}
New Page ${url2}
Page Switch tests
[Tags] UI dev
Switch to Browser1
Get Element text=Gmail
Switch to Browser2
Get Element text=© 2021 Microsoft
** Keywords **
Switch to Browser2
Switch Page ${browser_ids}[1]
Switch to Browser1
Switch Page ${browser_ids}[0]
Store Active Browser Id
${active_id}= Get Page Ids ACTIVE ACTIVE ACTIVE
Log To Console ${active_id}
${active_id}= Split String ${active_id}[0] =
Log To Console ${active_id}[1]
Append To List ${BROWSER_IDS} ${active_id}
*** Settings ***
Library Browser
Suite Setup Setup
*** Test Cases ***
Do something with page1
Switch Page ${PAGE1}
Do something with page2
Switch Page ${PAGE1}
Page switchy
Switch Page ${PAGE1}
Get Element text=Gmail
Switch Page ${PAGE2}
Get Element text=© 2021 Microsoft
*** Keywords ***
Setup
${PAGE1}= New Page https://www.google.com
Set Suite variable ${PAGE1}
${PAGE2}= New Page https://www.bing.com
Set Suite variable ${PAGE2}
Browser library has automatic teardown for Browser/Context/Page instances, so you have to create all needed instances of those in Suite Setup. Solution below:
*** Settings ***
Library Browser
#Library OperatingSystem
Library Collections
Library String
Suite Setup Create Suite Ecosystem
*** Variables ***
#{bids}
#{cids}
#{pids}
${url1}= https://www.google.com
${url2}= https://www.bing.com
*** Test Cases ***
Setup Verification
[Tags] UI dev
${bids}= Get Browser Ids
Log To console ${bids}
${bids}= Get Context Ids
Log To console ${cids}
${pids}= Get Page Ids
Log To console ${pids}
Page Switch tests
[Tags] UI dev
Switch to Page 1
Get Element text=Gmail
Switch to Page 2
Get Element text=© 2021 Microsoft
** Keywords **
Switch to Page 1
Switch Page ${pids}[0]
Switch to Page 2
Switch Page ${pids}[1]
Store Active Browser Id
${active_id}= Get Browser Ids ACTIVE
#${active_id}= Split String ${active_id}[0] =
Log To Console ${active_id}[0]
Append To List ${bids} ${active_id}[0]
Store Active Context Id
${active_id}= Get Context Ids ACTIVE ACTIVE
Log To Console ${active_id}
# ${active_id}= Split String ${active_id}[0] =
Log To Console ${active_id}[0]
Append To List ${cids} ${active_id}[0]
Store Active Page Id
[Arguments] ${new_id}
${active_id}= Get Page Ids ACTIVE ACTIVE ACTIVE
# ${active_id}= Split String ${active_id}[0] =
Log To Console ${active_id}[0]
Append To List ${pids} ${new_id}
Create Suite Ecosystem
# Create 1B-1C-2P Ecosystem
# 1st Browser
New Browser chromium headless=false
Store Active Browser Id
# 1st Context of 1st Browser
New Context viewport={'width': 1920, 'height': 1080}
Store Active Context Id
# 1st Page of 1st Context of 1st Context
New Page ${url1}
${current}= Switch Page CURRENT
Store Active Page Id ${current}
# 2nd Page of 1st Context of 1st Context
New Page ${url2}
${current}= Switch Page CURRENT
Store Active Page Id ${current}
Related
I want to speed up the loading time for pages on selenium because I don't need anything more than the HTML (I am trying to scrape all the links using BeautifulSoup). Using PageLoadStrategy.NONE doesn't work to scrape all the links, and Chrome no longer supports PageLoadStrategy.EAGER. Does anyone know of a workaround to get PageLoadStrategy.EAGER in python?
ChromeDriver is the standalone server which implements WebDriver's wire protocol for Chromium. Chrome and Chromium are still in the process of implementing and moving to the W3C standard. Currently ChromeDriver is available for Chrome on Android and Chrome on Desktop (Mac, Linux, Windows and ChromeOS).
As per the current WebDriver W3C Editor's Draft The following is the table of page load strategies that links the pageLoadStrategy capability keyword to a page loading strategy state, and shows which document readiness state that corresponds to it:
However, if you observe the current implementation of of ChromeDriver, the Chrome DevTools does takes into account the following document.readyStates:
document.readyState == 'complete'
document.readyState == 'interactive'
Here is a sample relevant log:
[1517231304.270][DEBUG]: DEVTOOLS COMMAND Runtime.evaluate (id=11) {
"expression": "var isLoaded = document.readyState == 'complete' || document.readyState == 'interactive';if (isLoaded) { var frame = document.createElement('iframe'); frame.name = 'chromedriver dummy frame'; ..."
}
As per WebDriver Status you will find the list of all WebDriver commands and their current support in ChromeDriver based on what is in the WebDriver Specification. Once the implementation are completed from all aspects PageLoadStrategy.EAGER is bound to be functionally present within Chrome Driver.
You only use normal or none as the pageLoadStrategy in chromdriver. So either choose none and handle everything yourself or wait for the page load as it normally happens
I want to automate mail checking on temp-mail.org
But the problem is the page keeps on refreshing internal components of page and therefore Selenium can't target mail.
My code:
mail= browser.find_element_by_xpath('//tbody/tr/td[#title="__mail title__"]')
mail.click()
But there is no response.
Then I noticed that contents of page are auto refreshing internally.
So how to stop this auto refreshing?
How about stopping the script aftre 3/5 secs of its runtime.
Try this :
fire = webdriver.FirefoxProfile()
fire.set_preference("http.response.timeout", 3)
fire.set_preference("dom.max_script_run_time", 3)
driver = webdriver.Firefox(firefox_profile=fire)
driver.get("url")
Scenario:
I have created an app in Meteor 1.5 and the problem is that when I run Meteor.Collection.get('CollectionName').find().fetch() inside chrome/firefox console, I see results.
Requirement:
Meteor.Collection.get('CollectionName') should be disabled on browser console.
It must show below error message if we try to access Collection using get()
Uncaught TypeError: Meteor.Collection.get is not a function
Analysis and expert's view
I got a comment to check if dburles:mongo-collection-instances is installed. But it was not in my package either. I am stuck as which package is allowing me to view collection on browser console.
My Meteor package list:
meteor-base#1.1.0
mobile-experience#1.0.4
mongo#1.1.18
blaze-html-templates
reactive-var#1.0.11
tracker#1.1.3
standard-minifier-css#1.3.4
standard-minifier-js#2.1.0
es5-shim#4.6.15
ecmascript#0.8.0
kadira:flow-router
kadira:blaze-layout
less#2.7.9
practicalmeteor:mocha
johanbrook:publication-collector
momentjs:moment
twbs:bootstrap
ian:accounts-ui-bootstrap-3
accounts-password#1.3.6
aldeed:collection2
check#1.2.5
ostrio:loggerfile
mizzao:user-status
gwendall:auth-client-callbacks
meteorhacks:ssr
bryanmorgan:webshot
manuelro:blaze-math
awatson1978:browser-detection
mrt:flash-messages
babrahams:transactions
themeteorchef:bert
session#1.1.7
iain:accounting
alanning:roles
reywood:publish-composite
aslagle:reactive-table
natestrauser:select2
dynamic-import
aldeed:autoform
percolate:synced-cron
mixmax:smart-disconnect
pfafman:filesaver
harrison:papa-parse
cfs:standard-packages
cfs:filesystem
tmeasday:publish-counts
maazalik:highcharts
jcbernack:reactive-aggregate
email
tsega:bootstrap3-datetimepicker
I included this in my chrome extension manifest
"devtools_page": "devtools.html"
And in devtools.html I include a devtools.js file which creates a panel
chrome.devtools.panels.create("Panel", "icon.png", "panel.html", function(panel){});
The panel is indeed created. And in panel.html I include a panel.js file in which I added a listener
chrome.devtools.network.onRequestFinished.addListener(function(details){
console.log(details);
});
But where can I see the console output of the panel? Or how can I redirect it to the devtools console?
This message will be logged in the console of the developer tools. To view this console, detach the developer tools from the window, and press Ctrl + Shift + J.
Here's an picture:
1. Page (http://host/)
2. + Devtools instance for http://host
3. + Devtools instance for chrome-devtools://devtools/devtools.html?... )
Your message is currently logged to 3 (the console of the devtools instance) instead of 2 (the console of the page). To log the string to the page, use the chrome.experimental.devtools.console API.
An alternative is to JSON-serialize your object, and use chrome.devtools.inspectedWindow.eval to log the result:
var obj = ...;
var str = JSON.stringify( obj );
chrome.devtools.inspectedWindow.eval('console.log(' + str + ');');
Another way to do it is to open the chrome devtools in a separate window (not on the side of the browser) and then press CMD + Option + i (for Mac) and then you get another devtools for that devtools. There you can debug and see console logs easier :)
I have a google chrome extension that shares some code between it's content script and background process / popup. If it some easy and straightforward way for this code to check if it's executed as content script or not? (message passing behavior differs).
I can include additional "marker" javascript in manifest or call some chrome fnction unavailable from content script and check for exceptions - but these methods looks awkward to be. Maybe it's some easy and clean way to make this check?
To check whether or not your script is running as a content script, check if it is not being executed on a chrome-extension scheme.
if (location.protocol == 'chrome-extension:') {
// Running in the extension's process
// Background-specific code (actually, it could also be a popup/options page)
} else {
// Content script code
}
If you further want to know if you're running in a background page, use chrome.extension.getBackgroundPage()=== window. If it's true, the code is running in the background. If not, you're running in the context of a popup / options page / ...
(If you want to detect if the code is running in the context of an extension, ie not in the context of a regular web page, check if chrome.extension exists.)
Explanation of revised answer
Previously, my answer suggested to check whether background-specific APIs such as chrome.tabs were defined. Since Chrome 27 / Opera 15, this approach comes with an unwanted side-effect: Even if you don't use the method, the following error is logged to the console (at most once per page load per API):
chrome.tabs is not available: You do not have permission to access this API. Ensure that the required permission or manifest property is included in your manifest.json.
This doesn't affect your code (!!chrome.tabs will still be false), but users (developers) may get annoyed, and uninstall your extension.
The function chrome.extension.getBackgroundPage is not defined at all in content scripts, so alone it can be used to detect whether the code is running in a content script:
if (chrome.extension.getBackgroundPage) {
// background page, options page, popup, etc
} else {
// content script
}
There are more robust ways to detect each context separately in a module I wrote
function runningScript() {
// This function will return the currently running script of a Chrome extension
if (location.protocol == 'chrome-extension:') {
if (location.pathname == "/_generated_background_page.html")
return "background";
else
return location.pathname; // Will return "/popup.html" if that is the name of your popup
}
else
return "content";
}