I am trying to get control of the existing chrome browser and want to use the same browser for automation, using selenium & Karate.
Here is an actual scenario:
I click a hyperlink from the desktop and it opens in the chrome browser. Now I need to run my automation script in the same browser.
I have the following code, before that, I am starting chrome browser in debugging mode using this link https://harith-sankalpa.medium.com/connect-selenium-driver-to-an-existing-chrome-browser-instance-41435b67affd
* def startUrl = "https://google.com"
* def browser = "chrome"
* def type = "chromedriver"
* def executable = "C:/chromedriver/" + type + ".exe"
* def driverConfig = { type: #(type), showDriverLog: true, start:false, executable: #
(executable), webDriverSession: { desiredCapabilities: { browserName: #
(browser),goog:chromeOptions": { debuggerAddress: 127.0.0.1:9223 } } } }
* configure driver = driverConfig
Given driver startUrl
* waitFor('input[name=q]')
And input('input[name=q]', 'Youtube')
can anyone please confirm how it will be done? I am new to Karate-UI
Getting control of an existing Chrome instance to use Karate UI is only possible if that Chrome instance has been started with remote-debugging enabled.
From the command-line, this is typically done by adding this option: --remote-debugging-port=9222.
I know a team that uses Karate UI for automating CEF (Chromium Embedded Framework) used in a desktop application. In this case, the developers of the desktop app made an environment variable drive the enabling of this debug mode. For e.g. if the OS env variable ENABLE_CHROME_DEBUG had a value equal to true, the CEF remote-debugging would be programmatically enabled via the SDK / API.
So you have to figure out some similar approach. If the desktop app is creating a new instance of Chrome, it should be possible to enable the remote debugging also - and you should work with the development team to make this "switchable" for the sake of testability.
Once that is done, Karate has a way to "attach" to an existing Chrome instance via the remote-debug protocol. Refer the docs: https://github.com/intuit/karate/tree/master/karate-core#configure-driver
And note the attach config key:
optional, only for type: 'chrome' and start: false when you want to attach to an existing page in a Chrome DevTools session, uses a "contains" match against the URL
So if you know the URL that has been opened in the browser you want to attach to (even if it is about:blank) you can now proceed with testing. You will need only these keys in the configure driver data:
type: 'chrome'
start: false
attach: 'some/url' - since this is a "contains" match, the http or https part can be omitted
port: 9222 - change this to use the actual port if different
And executable etc. is not needed.
Be aware of a certain quirk when you combine Desktop and Browser testing: https://github.com/intuit/karate/issues/1549#issuecomment-821265333
Related
I want to test a Chrome extension and to test it I need to have it browse the web randomly and visit random pages for a long period to see if it generates any errors. You need to be logged into the extension, which is why I am not using Selenium for this as I cannot find a way to log into the extension using Selenium.
Is there a way to make Selenium act on an existing or pre-set Chrome existence? Any other options?
You can use web-ext. You can use Firefox, google Chrome, Chromium.
You can script your browser like this.
import webExt from 'web-ext';
webExt.cmd.run({
// These are command options derived from their CLI conterpart.
// In this example, --source-dir is specified as sourceDir.
firefox: '/path/to/Firefox-executable',
sourceDir: '/path/to/your/extension/source/',
}, {
// These are non CLI related options for each function.
// You need to specify this one so that your NodeJS application
// can continue running after web-ext is finished.
shouldExitProgram: false,
})
.then((extensionRunner) => {
// The command has finished. Each command resolves its
// promise with a different value.
console.log(extensionRunner);
// You can do a few things like:
// extensionRunner.reloadAllExtensions();
// extensionRunner.exit();
});
There should be an option to define --start-url. You can make this a random url with some programming... Not able to test it now, but you should be able to make it work
Or you just run from the commandline
web-ext run --start-url www.mozilla.com
I was not able to find a tutorial that uses nightwatch js and local selenium grid (stuck on how to update the nightwatch.conf.js file correctly). I want to run a nightwatch test using selenium grid but was not successful.
I followed this guide = https://www.guru99.com/introduction-to-selenium-grid.html (but I used nightwatch and not java)
Here is my setup (Machine A is on Virtual Box, I can ping vise-versa Windows 10 host):
Machine A (hub) = Mint OS running selenium grid, ip = http://192.168.56.102/
Machine B (node) = Windows 10 OS, ip = http://192.168.56.1
So only thing left to do is update the "nightwatch.conf.js" file and run the test
Here is what I updated:
This is the error that I get:
This will work only when the selenium server is running in your machine. Grid is a setup where the server is running in a different machine. Below settings should work for you.
Replace webdriver: {}, with below code and selenium_host & selenium_port from your current config.
selenium: {
host: 192.168.56.102
port: 4444
}
Please refer to WebDriver Settings section of official docs here.
I am currently trying to test an app using webdriverio and chrome. But the app does not display anything but the images and some borders (??)(see pic). I get the same behaviour also with other websites, so it is not a problem of the app under test. Everything also displays well using other browsers (e.g firefox)
how it displays in chrome browser
Update: after searching a little bit more, I think this has something to do with passing basic auth credentials in the url, because the page I am testing is password protected. I have this in the webdriverio config file:
capabilities: [{
browserName: 'chrome',
chromeOptions: {
args: ['--disable-blink-features=BlockCredentialedSubresources']
}
}]
I am also using selenium-standalone as a service, version 0.0.10, webdriverio version 4.13.1.
In my code I open the page using:
browser.url("https://user:password#mywebsite.com/kontakt/");
I'm trying to get PhantomJS working with Protractor. I'm currently having an issue with Phantom, but not Chrome, when my code needs to reach a backend endpoint which is kept on a separate server. As such, I would like to test it with the --ignore-ssl-errors option.
Unfortunately, the example config file provided in the Protractor documentation doesn't seem to list any way to pass arguments to the browser. Is this possible?
It turns out the answer was in a closed Protractor issue: https://github.com/angular/protractor/issues/150
You CAN pass arguments to the browser with the phantomjs.cli.args property, which takes an array of arguments. Just add it to the capabilities property in your configuration, in he same location where you specify the browserName:
capabilities: {
browserName: 'phantomjs',
'phantomjs.binary.path': require('phantomjs').path,
'phantomjs.cli.args': ['--web-security=false', '--ignore-ssl-errors=true', '--webdriver-loglevel=DEBUG'],
}
I am super confused with selenium.
Completely new to automated testing and struggling to get a foothold with selenium.
http://www.seleniumhq.org/projects/webdriver/
I get the concept of writing tests and have done a few with in angular with protractor, but i need to use selenium for a particular project and not sure where to start.
To start with I just want to be able to write some simple client side tests, but i have no idea where to start with on Selenium, i read their docs but not really any the wiser..
A webdriver test is just a script, written in one of many compatible languages (java, python, etc). The script runs on any machine. During development it will typically run on your local machine, but eventually your test could run on a continuous integration server.
Webdriver has two modes of operation: it can open a browser on the same machine that the script is running, or it can send a request to a selenium grid hub, which will open a browser on one of its nodes.
As a simple example, here is a complete working example of a selenium test in python (taken from python selenium bindings Getting Started page):
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
If you have python and the selenium libraries installed, you can save this file to "example_test.py" and then run it from a command prompt with python example_test.py
Here's a similar test, this one in javascript, taken from the WebDriverJS User's Guide. You would run it the same way you run any javascript program.
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
return driver.getTitle().then(function(title) {
return title === 'webdriver - Google Search';
});
}, 1000);
driver.quit();
To give you an organic answer to your question, when you run a selenium Firefox browser test, it starts a local ad-hoc "Selenium grid hub listener" on a port like 30005 or something at the start of the test. Then, the code that you write talks to that local port in JSON format by sending local http requests to localhost:30005 . The "Grid hub" listening on that port knows how to talk to your local web browser and controls it by answering commands passed through that port. At the end of the test, the "selenium grid hub listener port" closes.
If you do some reading and try to understand how the "Selenium Grid Hub" works and also learn about "WebDriver Wire Protocol", then it might help you start understanding what I explained above.
Always read the official Selenium docs for references, but if you are using Java, you can get a head-start by using the Conductor framework
It's a Java specific DSL, so won't work with any other.
A test would look like this:
#Config(url="http://google.com", browser=Browsers.CHROME)
public class MyTest {
#Test
public void testGoogle() {
// a quick google search
setText(By.name("q"), "something")
.click("[name='btnG']");
}
}