Unable to run chrome with Testcafe on macOS - macos

I have been trying without success to run tests on chrome using Testcafe in MacOS. I have generated all the certificates required but when launching chrome with testcafe it reports ERR_SSL_VERSION_OR_CIPHER_MISMATCH. Below are the arguments I am passing -
yarn run testcafe --hostname localhost --ssl 'pfx = testingdomain.pfx;rejectunasuthorized=true;--ssl key = testingdomain.key;cert=testingdomain.crt' "chrome --use-fake-ui-for-media-stream --allow-insecure-localhost --allow-running-insecure-content" e2e/testmac.js --live
When I remove loading PFX cert and run below, I am able to get to the webpage, but cant access mic and camera. My command to maximzie browser window also does not work
yarn run testcafe --hostname localhost "chrome --use-fake-ui-for-media-stream --allow-insecure-localhost --allow-running-insecure-content --live" e2e/testmac.js --ssl 'key=testingdomain.key;cert=testingdomain.crt' --live
My simple test -
import { Selector, ClientFunction } from 'testcafe';
fixture`Audio Configuration Combination`.page`http://XXX.XXX.XXXXXX/sandbox/index.html`;
test('Launch SDK,', async (browser) => {
await browser.getCurrentWindow().maximizeWindow().wait(100000);
});
I have problems only on mac. Same setup is working fine on windows. I need to access mic and camera and so passing in "--use-fake-ui-for-media-stream". But I dont see a camera preview. Passing in "--use-fake-device-for-media-stream" loads up fake devices which is something I dont need.
Any help is greatly appreciated.

According to this comment on GitHub, it should be sufficient to use either of the two approaches to mock user media, not necessarily both. If you specify testcafe --hostname localhost, you shouldn't need to specify --ssl at all.
I ran the following test from the GitHub discussion mentioned above on macOS:
mock-media-test.js
fixture `WebRTC`
.page`https://webrtc.github.io/samples/src/content/getusermedia/canvas/`;
test(`test`, async t => t.wait(30000));
I used the following command:
testcafe "chrome --use-fake-ui-for-media-stream" mock-media-test.js --hostname localhost
The test ran as expected, and the page displayed the stream from my camera. The --use-fake-device-for-media-stream flag worked for me as well.

Related

Protractor 7 does not go beyond 'Using FirefoxDriver directly...'

I am unable to run e2e tests with protractor 7 with the following configuration
...
directConnect: true,
capabilities: {
browserName: 'firefox'
}
...
on my MacOS Catalina. I noticed the
webdriver-manager update
command from the project's package.json downloads the geckodriver-v0.29.1.
As mentioned in the title the logs do not go beyond Using FirefoxDriver directly... when I run the tests. How can I check logs in more details (is there a verbose option in protractor?), and how can I fix the issue ?
With Splaktars answer I was able to get Firefox to launch using the typical directConnect: true setting.
I had to download the geckodriver-v0.29.1-macos.tar.gz package from the Github Releases and extract the binary. Then I replaced the geckodriver-v0.29.1 binary previously downloaded through webdriver-manager with that copy from the package.
After that I launched my tests to make sure everything was still partially working and finally saw the MacOS security popup. I ran the command to remove the quarantine flag:
xattr -r -d com.apple.quarantine /path/to/geckodriver-v0.29.1
Relaunched the tests and finally Firefox popped up...
Thanks again to Splaktar, just made an account so I can't comment or upvote for help
It looks like there is a known issue in the v0.29.1 release notes:
https://github.com/mozilla/geckodriver/releases/tag/v0.29.1
Those point to some GeckoDriver macOS Notarization docs:
https://firefox-source-docs.mozilla.org/testing/geckodriver/Notarization.html
However that page say
Arbitrary software downloaded through other means, such as curl(1) is not affected by this change.
I don't get any security pop ups or warnings, just the hang that you see.
Running
xattr -r -d com.apple.quarantine /Users/splaktar/Git/app/node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.29.1
Doesn't help.
In https://github.com/angular/protractor/issues/4253, there are a lot of old issues mentioned with Firefox and directConnect support. I tried using directConnect: false with a suggestion from that issue:
config.capabilities = {
'browserName': 'firefox',
'marionette': true,
'elementScrollBehavior': 1
};
config.directConnect = false;
config.seleniumAddress = 'http://localhost:4444';
config.localSeleniumStandaloneOpts = {
jvmArgs: ['-Dwebdriver.gecko.driver=node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.29.1']
};
I ran webdriver-manager start and then ran my tests, but that failed quickly with an error page's HTML in the console and From: Task: WebDriver.createSession() Process exited with error code 199.
I also tried setting
config.firefoxPath = '/usr/local/bin/firefox-bin';
after creating a symbolic link there to /Applications/Firefox.app/Contents/MacOS/firefox-bin. But that didn't help at all. Firefox never gets started. I tried with Firefox Developer Edition as well.
Still investigating...

Change browser in runtime with cypress

I have 2 tests running using command:
await cypress.run({
browser: "chrome"
})
How can i run second test on eletron with out changing much in config file. Can i use Cypress.config() in my second test to pass browser as electron?

Not able to change default download directory for chrome with selenium hub docker and ruby watir

After a few days of searching and experimenting with any of the solutions I could find online, I give up and want to get some help from the community.
Ruby gems (ruby 2.5.1):
watir 6.11.0
selenium-webdriver 3.4.1
Docker:
selenium/node-chrome-debug:3.14
selenium/hub:3.14
My ruby code:
prefs = {
download: {
prompt_for_download: false,
default_directory: download_directory
}
}
browser = Watir::Browser.new(:chrome, url: selenium_hub_url, options: {prefs: prefs})
Our set-up is:
Run a selenium/hub and a selenium/node-chrome-debug. Something that might be different is that we are mounting the /tmp of the base OS as /hosttmp/tmp in the node container
Make the selenium/node-chrome-debug talk to selenium/hub
Make the browser automation talk to the selenium/hub using the code provided above
The problem is that I was never able to set the default download directory. However, all other parts are working correctly. The VNC window shows the browser is working correctly despite the default download directory settings. It is always /home/seluser/Downloads
Things I have tried:
Other people's ideas such as different ways to specify the options and preferences. (e.g. using the Capabilities)
Docker security-related settings such as: --privileged --security-opt apparmor:unconfined --cap-add SYS_ADMIN
On the base OS, chmod 777 for the download_directory. The download_directory, for example, /tmp/tmp.123 on the base OS, which is mounted as /hosttmp/tmp/tmp.123 in the chrome node container, I could see it and make a few read/write operations in this folder inside the container or on the base OS
Tweaks about the interesting ruby symbol/string stuff when creating a Hash object.
Does anyone have more ideas about what could lead to this situation? What else I could try? And is there any log that I could refer to. There is no error or warning when running the code. Thanks in advance.
I'm using Java+Docker+Selenium+Chrome for automation test and also met similar issue with you. Please find my solutions below and try if it works for your case.
Don't set default download directory in the options, just leave "/home/seluser/Downloads" as it is.
When you start up the chrome node on docker, please add the parameter of volume that could transfer the downloaded files to the directory you want.
e.g. docker run -d -p 5900:5900 --link myhub:hub -v :/home/seluser/Downloads selenium/node-chrome-debug:3.14.0
In my case, the JDK environment and my test script is on Linux machine while the selenium webdriver & browser are all on docker, so once the file downloaded by browser it cannot saved directly on Linux machine, you have to mount the local directory with default directory on docker. Then you could find the file saved in the directory you want.
Thanks & Regards!
Jing
Did you define options = Selenium::WebDriver::Chrome::Options.new?
We use
options = Selenium::WebDriver::Chrome::Options.new
prefs = {
prompt_for_download: false,
default_directory: download_directory
}
options.add_preference(download: prefs)
and then you would want something like
browser = Watir::Browser.new(:chrome, url: selenium_hub_url, options: options)
But maybe the main problem is just that you are using
options: {prefs: prefs}
instead of
options: {download: prefs}
Okay, by digging into the source code of the Watir and Selenium-Webdriver, I think I know the 'root cause'.
I have created an issue since I am not sure if this is a bug or a 'feature' The issue
Also, I have a workaround for my case, in watir/capabilities.rb:
Change
#selenium_browser = browser == :remote || options[:url] ? :remote : browser
to
#selenium_browser = browser == :remote ? :remote : browser
This shouldn't be the final solution as it might not be a good idea. Will wait for what the Watir people say about this.

D3, loading a csv file, filepath issue ? [duplicate]

I'm just learning d3, and I'm attempting to import data from a CSV file, but I keep getting the error "XMLHttpRequest cannot load file:///Users/Laura/Desktop/SampleECG.csv. Cross origin requests are only supported for HTTP. ". I've searched for how to fix this error and have ran it on a local web server, but I haven't found a solution that works for d3.v2.js. Here's a sample of the code:
var Time = []
ECG1 = []
d3.csv("/Desktop/d3Project/Sample.csv", function(data)
{
Time = data.map(function(d) {return [+d["Time"]];});
ECG1 = data.map(function(d) {return [+d["ECG1"]];});
console.log(Time)
console.log(ECG1)
});
Any help will be much appreciated.
This confused me too (I am also a d3 beginner).
So, for some reason, web browsers are not happy about you loading local data, probably for security reasons or something. Anyways, to get around this, you have to run a local web server. This is easy.
In your terminal, after cd-ing to your website's document root (thanks #daixtr), type:
python -m SimpleHTTPServer 8888 &
Okay, now as long as that terminal window is open and running, your local 8888 web server will be running.
So in my case, originally the web page I was working on was called
file://localhost/Users/hills/Desktop/website/visualizing-us-bls-data-inflation-and-prices.html
When I opened it in chrome. To open up my page on my local web server, I just typed (into the chrome search bar):
http://localhost:8888/Desktop/website/visualizing-us-bls-data-inflation-and-prices.html
Now, reading in CSVs should work. Weird, I know.
To those using built-in python webserver and who are still experiencing issues, do REMEMBER and make sure that you run the "python -m SimpleHTTPServer 8888" invocation at the correct path of which you consider to be your DocumentRoot. That is, you cannot just run 'python -m SimpleHTTPServer 8888' anywhere. You have to actually 'cd /to/correct/path/' containing your index.html or data.tsv and then from there run 'python -m SimpleHTTPServer 8888'.
Also, just learning D3 for school work. I was trying to run this simple D3 example:
https://gist.github.com/d3noob/b3ff6ae1c120eea654b5
I had the same problem as OP re: loading data using Chrome browser. I bet the great solution Hillary Sanders posted above was re: Python 2.X.
My answer is re: Python 3.X [OS: Ubuntu 16x]:
Open a terminal window within the root directory of your project, then run:
python3 -m http.server
It will serve HTTP on port 8000 by default unless it is already taken, in that case to open another port, e.g. 7800, run:
python3 -m http.server 7800
Then, on your Chrome browser address bar type:
localhost:8000
The above worked for me because I only had an index.html page in my root folder. In case, you have a HTML page with a different name, type the whole path to that local HTML page and it should work also. And, you should be able to see the graph created from the data set in my link (that must be in a folder like data/data.csv). I hope this helps. :-)
Use Firefox, idk what Chrome tries to accomplish

Selenium Error: no display specified

I've installed selenium-server-standalone-2.42.2.jar in a debian virtual box
and installed Firefox 29.0
and trying to run the following script with phpunit which is the only file in the directory:
<?php
class TestLogin extends PHPUnit_Extensions_Selenium2TestCase{
public function setUp()
{
$this->setHost('localhost');
$this->setPort(4444);
$this->setBrowser('firefox');
$this->setBrowserUrl('http://debian-vm/phpUnitTutorial');
}
public function testHasLoginForm()
{
$this->url('index.php');
$username = $this->byName('username');
$password = $this->byName('password');
$this->assertEquals('', $username->value());
$this->assertEquals('', $password->value());
}
}
I get the following error:
1) TestLogin::testHasLoginForm
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: Unable to connect to host
127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: no display specified
Error: no display specified
What does this mean?
I've red several threads and apparently I had to do the following which I tried:
1)to type this in the command shell
export PATH=:0;
Result: I got the same error.
2) I've installed vnc4server and getting debian-vm:1 as a application I then set export PATH=debian-vm:1 run it with realvnc and in the viewer (which works) I got the same problem.
You receive this error, because you have not set the DISPLAY variable. Here is a guide how to perform the test on a headless machine.
You have to install Xvfb and a browser first:
apt-get install xvfb
apt-get install firefox-mozilla-build
then start Xvfb:
Xvfb &
set DISPLAY and start Selenium:
export DISPLAY=localhost:0.0
java -jar selenium-server-standalone-2.44.0.jar
and then you will be able to run your tests.
These days setting up headless is as easy as passing an option to the selenium browser driver.
On most environments this can be done by setting the env variable MOZ_HEADLESS before running your tests, i.e try:
export MOZ_HEADLESS=1
Then, rerun your tests and it should run headless.
If you're out of luck, and it doesn't pick up the env var, try enabling the headless support in the driver config. E.g: with phpunit-selenium lib, do this:
Firefox
$this->setDesiredCapabilities(['moz:firefoxOptions'=> ['args' => ['-headless']]]);
Chrome
$this->setDesiredCapabilities(['chromeOptions'=>['args'=>['headless']]]);
See php-webdriver wiki for more selenium options.
Certainly scripting is the way to go, however iterating through all possible DISPLAY values is not as good as using the right DISPLAY value. Also there is no need for xvfb at least in debian/ubuntu. Selenium can be run locally or remotely using a current DISPLAY session variable as long as it is correct. See my post in http://thinkinginsoftware.blogspot.com/2015/02/setting-display-variable-to-avoid-no.html but in short:
# Check current DISPLAY value
$ echo $DISPLAY
:0
# If xclock fails as below the variable is incorrect
$ xclock
No protocol specified
No protocol specified
Error: Can't open display: :0
# Find the correct value for the current user session
$ xauth list|grep `uname -n`
uselenium/unix:10 MIT-MAGIC-COOKIE-1 48531d0fefcd0a9bde13c4b2f5790a72
# Export with correct value
$ export DISPLAY=:10
# Now xclock runs
$ xclock
The following is not the right variable:
$ export PATH=:0;
That defines where to find executables, such as in /bin, /usr/local/bin.
You're working with X11 variants and in that context, :0 refers to DISPLAY localhost:0.
So you probably intended the following:
$ export DISPLAY=:0
But as others have pointed out there needs to actually be an Xserver (virtual or otherwise) at that DISPLAY address. You can't just make up a value and hope it will work.
To find a list of DISPLAYs that your user is authorized to connect to you can use the following, then set your DISPLAY variable according (host:displayNumber, or :displayNumber if on the local host):
$ xauth list

Resources