How to take screenshot in headless mode in test framework with protractor/cucumber/typescript - protractor

I want to execute my test cases on headless mode and capture screenshots on failure.
I have included the below lines of code to run in the headless mode.
chromeOptions: {args: [ 'no-sandbox',"--headless", "--disable-gpu", "--window-size=800,600" ]},
This executes the test cases in the headless mode without issues. But on failure, it attaches white blank screenshot with the below code.
const screenshot = await browser.takeScreenshot();
scenario.attach(new Buffer(screenshot, 'base64'), "image/png");

For those who have the similar issue, below could be a problem which causing this issue-
I have used the below code to run in the headless mode
chromeOptions: {args: [ 'no-sandbox',"--headless", "--disable-gpu", "--window-size=800,600" ]},
After that, I had added code to maximize the screen due to which a blank image was taken as screenshot. I commented that code and executed and it worked fine!!!

Related

How to allow chrome browser notification in protractor e2e test for my Angular 9 web application

enter image description hereI need to allow the notification for the chrome browser to get incoming message notifications on my PC.
I have tried this code in the protractor.config file. It was still displaying the pop
capabilities: {
browserName: 'chrome',
'chromeOptions':{
'prefs' : {'profile.default_content_setting_values.geolocation': }
},
I have also tried using the following code in spec, it is not working
browser.switchTo().alert().accept()
for this code, I am getting an error as No such alert was found and the scripts fail.
Is there any provision to allow notification pop in the protractor for the chrome browser?
geolocation has nothing to do with it. You need to try these options https://chromium.googlesource.com/chromium/src/+/7e762c1f17514a29834506860961ba2f24e7e6e5/components/content_settings/core/common/pref_names.cc#36 Most likely these 3
"profile.default_content_setting_values.media_stream";
"profile.default_content_setting_values.media_stream_mic";
"profile.default_content_setting_values.media_stream_camera";
try these capabilities
{
browserName: 'chrome',
chromeOptions: {
prefs: {
'profile.default_content_setting_values.media_stream': 2,
"profile.default_content_setting_values.media_stream_mic": 2,
"profile.default_content_setting_values.media_stream_camera": 2
},
},
}

How do I see the logs of a VSCode Language Server process?

Situation
I'm experimenting with writing a VSCode Language Server Protocol (LSP) Extension. I've got it running as follows:
An lsp-server process which is launched by running haskell-lsp-example-exe from terminal
An lsp-client written in Typescript which, for now, basically just launches lsp-server (it's based on the lsp-sample repo)
The lsp-server is launch as follows:
# extension.ts
let serverOptions: ServerOptions = {
run: {
command: "haskell-lsp-example-exe"
},
}
The lsp-client is launched using code --extensionDevelopmentPath="path/to/extension"
I can see that it launches correctly, and I can find its pid through Activity Monitor (I'm on Mac).
Question
How can I see the logs of this process which is spawned by VSCode?
Context
I have tried the following:
In lsp-client/package.json I set the following which gives me the messages going back and forth. But not the logs of lsp-server.:
"languageServerExample.trace.server": {
"scope": "window",
"type": "string",
"enum": [
"off",
"messages",
"verbose"
],
"default": "verbose",
"description": "Traces the communication between VS Code and the language server."
}
I've also tried opening up dev tools in the launched instance of VSCode, but that gives the logs of lsp-client
The log labelled Log (Extension Host) in the launched instance of VSCode also doesn't look too useful
Thanks in advance for any help!

Multiple browsers are opened, but only one browser running spec. other browsers are idle

I am trying to achieve parallel test execution in protractor. With the below mentioned code, I can open multiple browser. But only one browser running the spec, rest are just opened.Below is the snippet in config file
capabilities: {
'browserName': 'chrome',
'shardTestFiles': true,
'maxInstances': 3
},
specs: ['Spec1.js',
'Spec2.js',
'Spec3.js'
],
Any help can be appreciated.
Try adding count to the browser capabilities and maxSessions to the config file

Protractor test fails on CI

Currently I am trying a setup an end to end protractor tests to a a bitbucket pipelines with set up an headless chrome and i am currently getting some error message:
Failed: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.
Any clue for this? how ever running tests locally is working fine; Can i set a constant session id?
Thanks
Check out your configuration file for this object
capabilities: {
"browserName": "chrome",
"chromeOptions": {
"args": ["incognito", "--window-size=1920,1080", "disable-extensions", "--no-sandbox", "start-maximized", "--test-type=browser"],
"prefs": {
"download": {
"prompt_for_download": false,
"directory_upgrade": true,
"default_directory": path.join(process.cwd(), "__test__reports/downloads")
}
}
}
},
When you find it, make sure you included "--no-sandbox" argument into args property.
What this guy does is it allows your tests to be ran from a remote container. In the meantime, if you include the argument when you run your tests on your machine, it has side effects like described here Chrome Instances don't close after running Test Case in Protractor

How to debug JavaScript tests in JHipster applications using Karma?

I have a simple monolithic application generated using JHipster v4.10.1 with front-end using Angular 4.x. To run JavaScript unit tests, as suggested in the documentation I ran
./node_modules/karma/bin/karma start src/test/javascript/karma.conf.js --debug
The command runs the tests, reports coverage summary and exits, whether tests all pass or some test fail does not matter. Test run output does show at one point that the debug server is loaded:
21 11 2017 13:41:20.616:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
But because the command exits, the Karma debug server can not be accessed. How to run tests so that Karma console can be used in browser to debug?
Figured out that the magic flag is actually single-run which seems to be true by default. So the main command to run for JS debug is:
yarn test --single-run=false
which in turn runs
$ karma start src/test/javascript/karma.conf.js --single-run=false
With this the command will only exit with explicit kill e.g. with Ctrl+C or Z. Karma debug console can then be accessed on http://localhost:9876/debug.html (assuming default port is not already busy. If it is, test output should tell you which port was chosen).
Additionally you need to disable minimization (and also istanbul config - not sure why) so that you can breakpoint and step through the .ts code in debugger easily. I figured this is done by making following changes in webpack/webpack.test.js file:
Remove following istanbul config from module.rules array:
{
test: /src[/|\\]main[/|\\]webapp[/|\\].+\.ts$/,
enforce: 'post',
exclude: /(test|node_modules)/,
loader: 'sourcemap-istanbul-instrumenter-loader?force-sourcemap=true'
}
Add minimize: false to the LoaderOptionsPlugin under plugins array:
new LoaderOptionsPlugin({
minimize: false,
options: {
tslint: {
emitErrors: !WATCH,
failOnHint: false
}
}
})