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.
Related
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
Im running chrome headless through chromedriver and selenium via python.
I've run into the following issue both on Mac and Linux.
Im starting chrome as follows:
if self.headless:
options.headless = True
options.add_argument("--headless")
if self.debug_port:
logging.info(f"Setting up remote debugging on port {self.debug_port}")
options.add_argument(f"--remote-debugging-port={self.debug_port}")
options.add_argument(f"--remote-debugging-address=0.0.0.0")
If I connect to http://localhost:9222 from another headed instance of chrome I can see the list of sessions and connect to it seamlessly. At which point i have a window opened up with a screencast of the remote session and the dev console.
Here's that successful example:
When I connect to http://192.168.1.194:9222 I get the list of sessions just fine and upon selecting one the dev console opens but it doesn't start the websocket connection to ws://192.168.1.194 so the screencast and remote debugging capabilities are not available.
Here's that failed example:
I've captured har files and uploaded them here if you want to take a look
Using the following steps I was able to debug remotely. However the screencast functionality did not work. Ultimately that's what I needed so this is only a 50% solution in my case.
So, as noted above in the comments, what's blocking remote debugging from working is that the chrome debugger links out to https://chrome-devtools-frontend.appspot.com/..... and passes a value of ws://192.168.1.194 for the websocket parameter. Any browser will inherently block this, based on it being mixed content - i.e: https + ws
What's needed here is to run the chrome dev tools frontend on a http server
and direct your chrome instance to that server instead of the appspot instance.
Solution Steps
1 Install depot_tools (pre-requisite for building)
https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up
2 Checkout the devtools-frontend repo
https://github.com/ChromeDevTools/devtools-frontend/blob/master/docs/workflows.md#checking-out-source
3 Build chrome devtools frontend
https://github.com/ChromeDevTools/devtools-frontend/blob/master/docs/workflows.md#build
4 Start the devtools-frontend http server
https://github.com/ChromeDevTools/devtools-frontend/blob/master/docs/workflows.md#running-in-hosted-mode
5 Run 2 instances of chrome and use one to debug the other
5.1 Start first instance of chrome headless
...with remote debugging enabled. See the python way in the question above or do it from the command line with the same arguments
5.2 Start a second instance of chrome
...using a different user data dir --user-data-dir=<some-path>
5.3 Navigate to http://192.168.1.194:9222
Use whatever the IP address of the first chrome instance is and the port that you chose.
5.4 Create a link to the local dev server
The 2nd instance of chrome will now be showing you links to debug each of the open tabs of the 1st instance. However the links will still to go https://chrome-devtools-frontend.appspot.com/..... You'll need to copy n paste the link you want and replace the hostname with the hostname of the devtools frontend that you started in step 4
Walla!!
If you figure out how to get the screencast working please comment below! 🙏
N.B:
I also tried using the npm run server command in the devtools frontend but for some reason that server didn't work at all ¯\_(ツ)_/¯
I am using Selenium to open a web site, login and copy some information from one web site. However it is happening on my work station and have a display monitor.
my IT team wants to move this process to a virtual server which does not have a monitor.
1.Will this work - even if we install Chrome of Firefox on the server
2. Can we Chrome - headless to make this happen
3. Any other way - we can think of using Xserver
Please let me know.
No . To run your script you don't need to have monitor. You can access your virtual machine through remote connection and you can start the execution from that machine. Once the execution started, you can close the remote desktop session and execution will continue to run on remote machine or virtual server.
I hope this helps. Please let me know if you have any further questions.
1.Will this work - even if we install Chrome or Firefox on the server - Yes it will work
2.Can we Chrome - headless to make this happen - If you are going to use virtual server just for execution,then you don't need to run in headless mode. Headless execution is needed for environments where you don't need a visible UI shell. Below code will help you run your script in headless mode
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu') # Last I checked this was necessary.
driver = webdriver.Chrome("/usr/local/bin/chromedriver", chrome_options=options)
driver.get("https://google.com")
#code to extract the details
driver.quit()
3.Any other way - we can think of using Xserver - Not sure
Chrome headless should solve your problem here -- I've done this in the past with some of my automation and had success.
Just remember to use ChromeOptions to add the --headless flag. You may need to tweak some other ChromeOptions as well -- I also had to add --disable-gpu and --window-size=1920,1200 to get mine working just right.
We are currently building a web interface for our manual QA team to be able to run Selenium tests, which are executed on remote machines via Selenium Grid.
I am looking for some way to remotely check if the Selenium Grid is currently executing any tests so I can then queue any additional runs sent to the Grid from the web interface until the previous test execution completes. This will ensure we avoid overloading the grid with too many simultaneous test runs.
I have searched through StackOverflow and read through the Selenium documentation to see if there were any commands that can be used to check for this, but came up empty.
You can see this details in grid console. For example if you are running the hub in local machine then the console URL is http://localhost:4444/grid/console. If you are running the grid hub on another machine then replace the local host with IP or hostname of the grid hub machine in the console URL.
There are many ways to know it.
If any of the node is occupied by test execution then the browser icon will be greyed out.(some times, you have to refresh the page to get status).
Otherwise if you mouse over on any browser icon in the console it will show the session ID if it is executing any test.
In selenium hub command line window logs. It will list out available nodes in a frequent interval.
You dont need to manage tests queue by yourself. Selenium grid and nodes have it in place. So for reducing overload on each nodes there are some configurations available. We have maxSession and maxInstance parameters.
maxSession - the maximum number of browsers that can run in parallel on the node
maxInstance - the maximum number of same browser instances that can run in parallel on the node.
F.e. maxSession = 3, maxInstance = 2. You can have 2 firefox + 1 chrome
You didnt mention what is your selenium driver version. so lets say its the newest 3.x.x. You can create node-config.json file and store there this parameters.
{
"capabilities": [
{
"browserName": "chrome",
"maxInstances": "2",#settings per browser
}
],
"maxSession": "3", #settings per node
}
To start the node:
java -jar /path_to_driver/serve.jar -role node -hub HUB_ADDRESS -nodeConfig /path_to_node_config/node-config.json
So when you want to run new test - grid will register it and will wait for a free node. So it can keep a stack for you
Also you can use bash command parallel and create an array of your tests and then run it in a parallel way. Lets say 5 jobs in parallel.
parallel --jobs 5 -k --gnu ::: "${arrayToRun[#]}"
More about Selenium configuration
More about run tests in parallel
I am running a simple java selenium test that opens an app http://localhost:8000/ but when selenium opens the application in IE10 it opens with 8002 port instead of 4444. Because of this it always leads to 404 error and when I change the port to 4444 the test proceeds fine.
This is happening only with IE10 on Windows 8. Other browsers (chrome/firefox) seem to run the test correctly on Windows 8.
I am using latest selenium v2.25.0. This is webdriver backed selenium but I am using legacy selenium apis (ex: selenium.open())
Anybody have suggestions on how to debug this issue?
Thank you in advance!
You can feed a port parameter to selenium when you are initializing it:
selenium = new DefaultSelenium("localhost", 4444, '*firefox', siteUrl);