Selenium/Watir can't detect Chromedriver, even though it's in my path (Windows 7) - selenium

I know there's another question similar to this, but the link provided by the answerer is out of date (and when I dig into the current Watir documentation I only find info on Windows 8.1; I am on Windows 7, and the step that doc suggests for resolving this is not helping me per below)
I am attempting to execute a test using Watir/minitest (along the lines of rake ci:setup:minitest test TEST=test/full_path/happypath_test.rb), and it chokes on the following:
Selenium::WebDriver::Error::WebDriverError: Unable to find the chromedriver exec
utable. Please download the server from http://chromedriver.storage.googleapis.c
om/index.html and place it somewhere on your PATH. More info at http://code.goog
le.com/p/selenium/wiki/ChromeDriver.
The Watir documentation and error message both point to the PATH. However, I have just downloaded the latest version of Chromedriver (2.12, it appears) and plonked the exe in a folder that I have confirmed is in my PATH (specifically c:/Ruby193/bin - yes I know I'm on an old Ruby version; alas not something I can update for this project)
I know Chromedriver is present because I can run it from irb:
require 'watir-webdriver
followed by
b = Watir::Browser.new :chrome
This launches a chrome window just fine. But when I actually try to execute a test it gives the "can't find chromedriver" error.
I've run bundle install to try and be sure I'm on the right versions of things and don't know what else to do. Any help, please?

Specify the driver_path directly to Selenium.
Simply call this before launching your new browser window:
Selenium::WebDriver::Chrome::Service.driver_path = "/absolute/path/to/chromedriver"
This also has the benefit of not requiring you to muck up your PATH and you can checkthis into your repo (of course, make the path dynamic to your project root directory, etc.).

I found real nice posts here and here. You can configure in super easy steps.
I have tried and tested working superb.
From post 1:
Change from firefox to chrome (wherever you have instantiated the browser ), so that it will become:
#browser = Watir::Browser.new :chrome
Now if you are on Windows, copy paste the downloaded binary file in C:/Windows directory`
Second post tells about how to change the default path c:\windows to your project's custom path. Its interesting and helpful. Take a look for sure.

Related

Getting 'Could not find test files' Error when attempting to run TestCafe tests

I'm trying to run some TestCafe tests from our build server, but getting the following error...
"Could not find test files at the following location: "C:\Testing\TestCafe".
Check patterns for errors:
tests/my-test.ts
or launch TestCafe from a different directory."
I did have them running or able to be found on this machine previously, but others have taken over the test coding and changed the structure a bit when moving it to a Git repository. Now when I grab the tests from Git and try to run, the problem presents itself. I'm not sure if there is something in a config file that needs adjustment but don't know where to start looking.
The intention is to have it part of our CI process, but the problem is also seen when I attempt to run the tests from the command line. The build process does install TestCafe, but there is something strange around this as well.
When the build failes with the can't find tests error, if I try to run the following command in the proper location...
tescafe chrome tests/my-test.ts
... I get, 'testcafe' is not recognized as an internal or external command,
operable program or batch file.
Just can't understand why I can't get these tests running. TestCafe setup was pretty much easy previously.
ADDENDUM: I've added a screenshot of the working directory where I cd to and run the testcafe command as well as the tests subdirectory containing the test I'm trying to run.
Any help is appreciated!!
testcafe chrome tests/my-test.ts is just a template; it isn't a real path to your tests. This error means that the path that you set in CLI is wrong, and there aren't any tests. You need to:
Find out where you start CLI. Please attach a screenshot to your question.
Define an absolute path to tests or a path relative to the place where CLI was started. Please share a screenshot of your project tree where the directory with tests is open.
Also, you missed t in the tescafe chrome tests/my-test.ts command. It should be tesTcafe chrome tests/my-test.ts. That is why you get the "'tescafe' is not recognized as an internal or external command" error.
I was able to get things working by starting from scratch. I uninstalled TestCafe and cleaned the working folder. During next build it was fine. I'm sure I've tried this several times, but it just started working.
One positive that came out of it was that I discovered a typo in a test file name, which was also causing issues finding the test I was using to check testing setup.
Thanks for helping!!

Changing default path for Chrome executable for karate-chrome

I am using the Karate framework to do the API testing. As part of CI efforts, we send an email at the end of test execution listing the summary of test results. There is a need to include the screeshot of the test execution counts from 'overview-feature.html' file.
I did so through the TestRunner.java file - launched Chrome using Chrome.start() and then using it to take screenshot. It all works well locally on Windows.
However when executing on CI server which is a Unix box, the chrome executable is not present in the default location (usr/bin/google-chrome) and hence the connection for the localhost fails.
Is there a way we can change the default location of the chrome executable?
PS: Apologies if this was too trivial to be asked.
Yes Chrome on CI is hard to get right, refer: https://stackoverflow.com/a/62325328/143475 - note that CI boxes typically are "headless" a browser may not be even installed.
I think the best thing for you is to ZIP the HTML and send it. But I really think you need to work with some CI experts, because the report generation and e-mailing business is normally done by things like Jenkins. What you are doing is certainly not normal or best-practice.
If you really want, there is a Karate Docker container that can give you a proper Chrome instance (see docs) but that is overkill for what you need.
EDIT: The Chrome Java API allows for customization of the executable path and this is in the docs: https://github.com/intuit/karate/tree/master/karate-core#chrome-java-api
It should be something like this:
Chrome.start("/opt/blah/chrome");

selnium chromedriver.exe executable needs to be in PATH [dup]

selenium not work, and tried many things
i know this has been ask allllllllot, but i dont know what's going on my computer
1. added enviorment path
2. basically put chromedriver.exe every location in my file
3. correct version (chromedriver and chrome)
4. added executable_path
5. i can opne chromedriver.exe in cmd
driver = webdriver.Chrome(options=chrome_options, executable_path=r'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')
all above is not work, i just wanna use selenium,any good idea? except reload system? (win10)
error pic
From the image picture , your chromedriver is clearly in the wrong path. Go to your command prompt , and run
chromedriver.exe
See if you are not able to execute it , it means that the path is incorrect.
Remedy
1) you need to make sure you have install Chrome.
2) Get the latest chrome driver here
3) Set path in your environment
4) In your script , this alone should work
browser = webdriver.Chrome()

Is it Firefox or Geckodriver, which creates "rust_mozprofile" directory

Whenever we invoke Firefox, under '/tmp' directory rust_mozprofile directories are getting created. As Firefox internally calls Geckodriver we are not sure whether Firefox or Geckodriver is creating rust_mozprofile directory.
I do want to know whether Geckodriver or Firefox because, my '/tmp' directory is having less memory.
So the question is I really want to modify the path of creating directories for rust_mozprofile.
I am using below technologies,
Selenium - 3.3.0
Firefox - 52.2.0
Geckodriver - 13
Please give us some suggestion, if there is any.
If you have a closer look at the geckodriver v0.18.0 logs closely you will observe the very first occurrence of rust_mozprofile occurs in the following line:
1504762617094 Marionette CONFIG Matched capabilities: {"browserName":"firefox","browserVersion":"56.0","platformName":"windows_nt","platformVersion":"6.2","pageLoadStrategy":"normal","acceptInsecureCerts":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"rotatable":false,"specificationLevel":0,"moz:processID":5848,"moz:profile":"C:\\Users\\AtechM_03\\AppData\\Local\\Temp\\rust_mozprofile.OfFuR9ogm33d","moz:accessibilityChecks":false,"moz:headless":false}
This log clearly indicates that marionette is being configured with:
"moz:profile":"C:\\Users\\AtechM_03\\AppData\\Local\\Temp\\rust_mozprofile.OfFuR9ogm33d"
And this configuration is done by the WebDriver instance i.e. the GeckoDriver.
It's the GeckoDriver which internally configures the Marionette which in-turn initiates the Mozilla Firefox Browser.
IMO, this workflow is in practice since we migrated from the Legacy Firefox to Marionette based Firefox. Hence the same must be the case with Geckodriver - 13 as well.
Update:
GeckoDriver as an application/exe file:
You can set the location with the TMPDIR envvar. It's also useful to set both TMP and TEMP for other programs.
A solution is to use driver.quit() this closes all browsers and takes care of the profiles
Another solution is to add a custom profile
fp = webdriver.FirefoxProfile('specify location to profile .default')
driver = webdriver.Firefox(firefox_profile=fp)
I had a similar problem and I solved it by changing the Environment settings in Windows. Meaning that I changed the directory for the TMP and TEMP files, and after a reboot, the rust_mozprofile folder was generated where I wanted it.
This is the source I used: https://www.toolsqa.com/selenium-webdriver/how-to-use-geckodriver/ Specifically the "Set property in Environment Variables:-" section.
Sadly this will effect all Software that saves files to those folders. (In my case that is what I wanted though.) If there is a way to make only the rust_mozprofile folder be created in a specific directory through the program, I would love to learn more.

PhantomJS -headless browseer

I have to automate a test case in which a list in a particular dashboard is created. We decided to use PhantomJS headless browser. Since I am new to it, I tried creating test myself. Following are the steps I followed just to open the target website.
Created directory phantoms
cd phantoms and installed phantom module using command npm install phantom --save
Created file createlist.js:
createlist.js contents:
var phantom = require('phantom');
var page = require('webpage');
page.open('http://facebook.com', function(status) {
console.log("Status: " + status);
if(status === "success") {
page.render('example.png');
}
phantom.exit();
});
When i execute command node create_list.js, I am getting the following error:
page.open('interact2.responsys.net/interact/jsp/jindex.jsp&#‌​39;, function(st atus) { ^ TypeError: page.open is not a function at Object.<anonymous> (C:\Users\shilshet\New folder\phantom\create_list.js:3 :6) at Module._compile (module.js:413:34)
If I try to execute command like
phantomjs C:/Users/shilshet/New folder/phantom/create_list.js
I am getting this error
bash: phantomjs: command not found
Note: I am using cygwin to execute commands
What I am going wrong? I installed phantomjs module also in the same folder as my node.js.
Could anyone let me know apart from using headless browser, how does one create a profile list in Oracle responsys via REST API call?
While the first answer here should work, it's not the best way to accomplish what you need. The cleaner way to solve your issue is to add the location of your phantomjs executable to your PATH variable defined in a file such as ~/.bash_history.
The file may not be defined, so you may need to create the file, and then add PATH="/path/to/phantomjs/executable"
If you prefer to edit your PATH var via a GUI: Edit PATH variable via Windows GUI
The reason you need to do this, is that your system natively iterates over paths defined in the 'PATH' variable in order to determine where executable files are. Since phantomjs is not included in the PATH variable (nonexistent in the environment), and you try to run 'phantomjs', your system simply does not know which executable to call (or rather it doesn't know it exists)
The reason this is the better approach is:
You don't need to explicitly write out the path of where phantomjs is located every time you want to run it (it's just cleaner looking too)
What happens if you you call phantomjs from multiple files, and the location of where phantomjs is stored changes? If you explicitly typed phantomjs' absolute path everywhere, then you need to change EVERY place you typed it! Nightmare! With this approach, you simply change it in one place; the file that defines your PATH variable
It's pretty conventional to add new file paths to your PATH env variable. You shouldn't clutter it, but it makes sense in this case to add it
For this: "Could anyone let me know apart from using headless browser, how does one create a profile list in Oracle responsys via REST API call?"... I would recommend asking a separate question. I personally don't know, but if you raise the new question, you may get support from someone who does.
Hope this helps! If you need any help whatsoever, let me know.
You mixed up two ways of running PhantomJS.
The more straightforward, more simple way is just launching PhantomJS from command line and giving it the path of a script as an argument. On Windows you would do it like this:
"C:/Users/shilshet/New folder/phantom/phantomjs.exe" "C:/Users/shilshet/New folder/phantom/create_list.js"
Note the quotes here, they're needed because there are spaces in filenames.