How can I run my tests with older chrome version in cypress - google-chrome

Now my cypress version is 3.8.2
And when I am opening cypress window there are chrome version is 79.
I want to run my tests in chrome 70 version. I updated my chrome in my computer and now it 70 version.
When I am running my test with selected command
npx vue-cli-service test:e2e --headless --browser chrome
Test is running in Chrome 79. How can I change my chrome version for running.

As per the documentation, the default chrome location to be auto-detected by cypress is "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe". If the other version of chrome is installed in a different location, I guess the available options are to uninstall both 79 & 70 and clean install 70 first to the above said location and later installing 79 to a different location (OR) uninstall 79 (assuming it installed in default location) and re-install to a different location than the default, and finally set a symbolic link to version 70 on the default location something like (which requires admin previleges on the machine, though). This way cypress scans the default location and gets whichever version pointing to the symbolic link.
mklin "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "path to ver70 exe"
But before all, I think the command parameters appear to be slightly off, can you try instead (making sure the path is pointing to the verion 70, not the default one)
npx vue-cli-service test:e2e --headless --browser "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
I suspect --headless is default for a 'cypress run' command command, if your test:e2e is something like "cypress run", then you can simply omit it.

The --browser command supports launching any supported browser by specifying a path to the binary.
So in your case try: npx vue-cli-service test:e2e --headless --browser /usr/bin/chromium
where /usr/bin/chromium is the path for the binary of your needed version of Chrome.

Related

VSCode open-in-browser won't open google-chrome (ubuntu)

When I try to run the open-in-browser extension (TechER version; there are a few such extensions by roughly the same name) in VS Code (1.41.1), I continually get the following error message: "Open browser failed!! Please check if you have installed the browser correctly!"
I reinstalled google-chrome, made sure it was default, double-checked the xdg settings, but it still won't work. Any suggestions much appreciated
It is because there is no binary executable named google-chrome may be yours is google-chrome-stable .
One thing you can do is to copy the binary file google-chrome-stable and create a renamed file google-chrome
Or you can set a bah alias
alias google-chrome='google-chrome-stable'
I was having this same issue with the "open in browser" extension. I clicked on the settings icon and installed an older version 1.1.0. Its working again for me.

headless Chrome - why doesn't it create screenshots?

I am following this manual
But for whatever reason my command in CLI does not produce any image:
C:\temp2>"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --disable-gpu --screenshot http://www.google.com
I have Chrome 62 (59+ needed).
I have full rights to C:\temp2
When I run only C:\temp2>"C:\Program Files
(x86)\Google\Chrome\Application\chrome.exe", Google Chrome starts up
which means that the path is correct.
I have Windows 7 Pro SP1 64bit.
What could be wrong?

Browser Automation using Bash On Ubuntu On Windows

We have a strong regression automation suite developed with Watir for Web Apps and Calabash for IOS and Android and so far our executions are happening on Mac OS.
We want to use RVM on Windows 10 so enabled bash feature on Windows 10 and installed RVM using Bash On Ubuntu On Windows. Using this installed RVM I would like to trigger the browsers installed on my Windows. I would like to know whether I am trying something that is possible ?
Just to check, I tried to trigger chrome browser in irb.
I placed my chrome driver below.
I have set my path and find the same below
On triggering chrome browser in irb I am getting the below error even though the path is set correct.
Selenium::WebDriver::Error::WebDriverError: Unable to find chromedriver.
I would like to know whether trying to trigger the browser installed on my windows environment through the Bash On Ubuntu On Windows terminal is practically possible attempt or not ? If so, please let me know where the disconnect had happened in my setup.
Below are the versions I am installed with .
rvm 1.29.3 (latest)
ruby-2.2.7
watir (6.8.4)
The error you are getting generally indicates that you have installed the chromedriver.exe file into a directory that is not on your path. Either move the file to a directory that is in the default path, or modify the path to add the directory with chromedriver.exe to the path.
Generally it's best to do that with the default path set by Windows on boot-up lest you have to have some batchfile that is run to alter the path before running IRB or a script that runs your tests.
Use the webdrivers gem. It ensures you always have the latest chromedriver.exe in your ~/.webdrivers directory, by downloading the newest version as necessary. It directs the Ruby code to use that driver regardless of what other chromedriver is on your system and whether it is or isn't on PATH.

How do I use Headless Chrome in Chrome 60 on Windows 10?

I've been looking at the following article about Headless Chrome:
https://developers.google.com/web/updates/2017/04/headless-chrome
I just upgraded Chrome on Windows 10 to version 60, but when I run either of the following commands from the command line, nothing seems to happen:
chrome --headless --disable-gpu --dump-dom https://www.google.com/
chrome --headless --disable-gpu --print-to-pdf https://www.google.com/
And I'm running all of these commands from the following path (the default installation path for Chrome on Windows):
C:\Program Files (x86)\Google\Chrome\Application\
When I run the commands, something seems to process for a second, but I don't actually see anything. What am I doing wrong?
Thanks.
Edit:
As noted by Mark Rajcok, if you add --enable-logging to the --dump-dom command, it works. Also, the --print-to-pdf command works as well in Chrome 61.0.3163.79, but you'll probably have to specify a different path for the output file in order to have the necessary permissions to save it.
As such, the following two commands worked for me:
"C:\Program Files (x86)\Google\Chrome\Application\chrome" --headless --disable-gpu --enable-logging --dump-dom https://www.google.com/
"C:\Program Files (x86)\Google\Chrome\Application\chrome" --headless --disable-gpu --print-to-pdf=D:\output.pdf https://www.google.com/
I guess the next step is being able to step through the dumped DOM like PhantomJS with DOM selectors and whatnot, but I suppose that's a separate question.
Edit #2:
For what it's worth, I recently came across a Node API for Headless Chrome called Puppeteer (https://github.com/GoogleChrome/puppeteer), which is really easy to use and delivers all the power of Headless Chrome. If you're looking for an easy way to use Headless Chrome, I highly recommend it.
This works for me:
start chrome --enable-logging --headless --disable-gpu --print-to-pdf=c:\misc\output.pdf https://www.google.com/
... but only with "start chrome" and "--enable-logging" and with a path (for the pdf) specified - and if the folder "misc" exists on the c-directory.
Addition: ... the path for the pdf - "c:\misc" above - can of course be replaced with any other folder/dir.
With Chrome 61.0.3163.79, if I add --enable-logging then --dump-dom produces output:
> "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --enable-logging --headless --disable-gpu --dump-dom https://www.chromestatus.com
<body class="loading" data-path="/features">
<app-drawer-layout fullbleed="">
...
</script>
</body>
If you want to programatically control headless Chrome, here's one way to do it with Python3 and Selenium:
In an Admin cmd window, install Selenium for Python:
C:\Users\Mark> pip install -U selenium
Download ChromeDriver v2.32 and extract it. I put the chromedriver.exe in C:\Users\Mark, which is where I put this headless.py Python script:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("headless") # remove this line if you want to see the browser popup
driver = webdriver.Chrome(chrome_options = options)
driver.get('https://www.google.com/')
print(driver.page_source)
driver.quit() # don't miss this, or chromedriver.exe will keep running!
Run it in a normal cmd window:
C:\Users\Mark> python headless.py
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" ...
... lots and lots of stuff here ...
...</body></html>
Current versions (68-70) seem to require --no-sandbox in order to run, without it they do absolutely nothing and hang in the background.
The full commands I use are:
chrome --headless --user-data-dir=tmp --no-sandbox --enable-logging --dump-dom https://www.google.com/ > file.html
chrome --headless --user-data-dir=tmp --no-sandbox --print-to-pdf=whatever.pdf https://www.google.com/
Using --no-sandbox is a pretty bad idea and you should use this only for websites you trust, but sadly it's the only way of making it work at all.
--user-data-dir=... uses the specified directory instead of the default one, which is likely already in use by your regular browser.
However, if you're trying to make a PDF from HTML, then this is fairly useless, since you can't remove header and footer (containing text like file:///...) and the only viable solution is to use Puppeteer.
You should be good. Check under the Chrome Version directory
C:\Program Files (x86)\Google\Chrome\Application\60.0.3112.78
For the command
chrome --headless --disable-gpu --print-to-pdf https://www.google.com/
C:\Program Files (x86)\Google\Chrome\Application\60.0.3112.78\output.pdf
Edit:
Still execute commands where the chrome executable is, in this instance
C:\Program Files (x86)\Google\Chrome\Application\
I know this question is for Windows, but since Google gives this post as the first search result, here's what works on Mac:
Mac OS X
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --headless --dump-dom 'http://www.google.com'
Note you MUST put the http or it won't work.
Further tips
To indent the html (which is highly desirable in real pages that are bloated), use tidy:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --headless --dump-dom 'http://www.google.com' | tidy
You can get tidy with:
brew install tidy
If you want to dodge on the problem in general, and just use a service of some kind to do the work for you, I'm the author/founder of browserless which attempts to tackle running headless Chrome in a service-like fashion. Other than that it's pretty tough to keep up with the changes and making sure all the appropriate packages and resources are installed to get Chrome running, but definitely doable.
I solved it by running this (inside chrome.exe directory),
start-process chrome -ArgumentList "--enable-logging --headless --disable-gpu --print-to-pdf=c:\users\output.pdf https://www.google.com/"
you can choose your own path.print-to-pdf=<<custom path>>

Universal path to chrome.exe

I am making an application and I want to make it installable on the user's desktops using chrome URL shortcut. Therefore, is there a universal path to the chrome.exe that can launch my app on all Windows versions ( XP, Seven and vista )
Chrome installs by default to the User's AppData Local folder:
XP:
C:\Documents and Settings\UserName\Local Settings\Application Data\Google\Chrome
Vista:
C:\Users\UserName\AppDataLocal\Google\Chrome
Windows 7:
C:\Program Files (x86)\Google\Application
Win 7/8/10/11, (either):
- C:\Program Files (x86)\Google\Chrome\Application
- C:\Program Files\Google\Chrome\Application
Best bet is to use some OS detection code, then use an environment variable to detect the User's AppData folder (i.e. %LOCALAPPDATA%) or the ProgramFiles folder, and then append the difference in OS's to the end of the variable.
You can look in the Registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe
The registry option might be the best, but the one suggested in the other answer didn't exist in my computer (Windows 10 64-bit). I think the "Uninstall" key might be more robust. If it didn't exist, users would have a hard time uninstalling Chrome. The following keys give you the install location, you'll need to append "\chrome.exe" to get the full path to the executable:
Chrome:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome\InstallLocation
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome\InstallLocation
Chrome Canary:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome SxS\InstallLocation
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome SxS\InstallLocation
Win 7 32 bit:
c:\Program Files\Google\Chrome\Application\chrome.exe
Win 7 64 bit (or W10 64b):
c:\Program Files (x86)\Google\Chrome\Application\chrome.exe
(which is different from the preceding answers and comments).
Clay Nichols suggestion to look in the registry is of course recommended.
Please do not edit!
Someone "edited" this answer saying 32 bit paths are always (x86), showing a total misunderstanding of the question and the answer! The path c:\Program Files (x86)\ does not even exist on a 32 bit machine (unless you manually add it youself); both of the above are tested answers.
For Windows users chrome.exe could have been be installed in several places based on the user's Window's edition (64 or 32-bit) and when the user installed Chrome it:
Current Locations
It'll most likely be in either:
C:\Program Files (x86)\Google\Chrome\Application
For 32-bit Chrome
Or 64-bit edition if you *installed Chrome before 2020. See: Windows Chrome 64-bit prepared to install into Program Files
C:\Program Files\Google\Chrome\Application
for Chrome 64-bit edition *(the default install location since 2020)
C:\Program Files\Google\Chrome\Application
For 32 bit Chrome on Windows 32-bit (Program Files (x86) is used only on windows 64-bit to denote 32-bit applications)
*Much confusion is caused by the fact that Chrome has been 64 bit since 2014, but Google still used Program Files (x86) until 2020 as the install location. And if you installed Chrome before 2020 then it will continue to live in the Program Files (x86) directory:
Browsers installed under "C:\Program Files (x86)" remain in that
directory and will continue to be updated. They must be uninstalled
first to be reinstalled under "C:\Program Files".
Legacy Locations
Chrome used to install to the user folder for Vista and XP:
XP:
C:\Documents and Settings\UserName\Local Settings\Application Data\Google\Chrome
Vista:
C:\Users\UserName\AppDataLocal\Google\Chrome
I had a .mht file that I would like to open in chrome, and found that just running:
chrome.exe "path-to-file.mht"
would work just fine! No need to find the path :)