Protractor functional test cannot load unsafe http javascript - npm

So I wrote a bookmarklet and want to do some functional testing, I used Protractor and I was able to inject my bookmarklet javascript file to it. However since it is hosted locally it is not HTTPS. When I run the test although the js file is injected, I got
VM122:17 Mixed Content: The page at 'https://xxxx' was loaded over HTTPS, but requested an insecure script 'http://localhost:8000/content.js'. This request has been blocked; the content must be served over HTTPS.
Since the browser is newly created every time the test runs I can't set the 'load unsafe script option' for testing.

You could start chromedriver with extra arguments in your Protractor configuration.
capabilities: {
browserName: "chrome",
chromeOptions: {
args: [
"--allow-running-insecure-content"
]
}
}
For a full list of chromedriver arguments, see:
http://www.assertselenium.com/java/list-of-chrome-driver-command-line-arguments/
https://sites.google.com/a/chromium.org/chromedriver/capabilities

Related

How can I browse the web randomly in a Chrome instance with a logged in Chrome extension?

I want to test a Chrome extension and to test it I need to have it browse the web randomly and visit random pages for a long period to see if it generates any errors. You need to be logged into the extension, which is why I am not using Selenium for this as I cannot find a way to log into the extension using Selenium.
Is there a way to make Selenium act on an existing or pre-set Chrome existence? Any other options?
You can use web-ext. You can use Firefox, google Chrome, Chromium.
You can script your browser like this.
import webExt from 'web-ext';
webExt.cmd.run({
// These are command options derived from their CLI conterpart.
// In this example, --source-dir is specified as sourceDir.
firefox: '/path/to/Firefox-executable',
sourceDir: '/path/to/your/extension/source/',
}, {
// These are non CLI related options for each function.
// You need to specify this one so that your NodeJS application
// can continue running after web-ext is finished.
shouldExitProgram: false,
})
.then((extensionRunner) => {
// The command has finished. Each command resolves its
// promise with a different value.
console.log(extensionRunner);
// You can do a few things like:
// extensionRunner.reloadAllExtensions();
// extensionRunner.exit();
});
There should be an option to define --start-url. You can make this a random url with some programming... Not able to test it now, but you should be able to make it work
Or you just run from the commandline
web-ext run --start-url www.mozilla.com

How to pass client cert and key for https tests in Protractor?

I want to run https tests using Protractor nodeJS framework. But my tests expect to pass cert and key.
I looked into Protractor, I could not find any option to pass cert and key.
You should be able to use acceptInsecureCerts field in the capabilities section of your config to get around this. The following example works for chrome and firefox. I'm not entirely sure what it is for other browsers but it will be similar to this.
capabilities: {
browserName: 'chrome',
acceptInsecureCerts : true
}

Browser URL does not loading when Protractor test runs remotely

I am trying to run my Protractor test on a remote server (selenium grid). I have Jenkin job to execute commands. When I run the exact test on my local server, the browser (both Firefox and Chrome works) get starts and load the URL and complete the tests. But when I execute via Jenkins it starts the browser but does not load the URLs. After some time Jenkins job gets timed out but still, browsers are open and do nothing. any idea? help much appreciated
I am passing the remote server as follows in my config.js,
seleniumAddress:http://citest-grid.com:4444/wd/hub
I managed to solve this issue removing 'disable-infobars' in the chromeOptions. But not sure why
'chromeOptions': {
'args': ['disable-infobars']
}
Check with the below code
capabilities: {
browserName: 'chrome',
directConnect: true //Hope by adding this your problem gets resolved
}
Remove seleniumAddress from your config.

Webdriverio with chrome browser does not display correcty

I am currently trying to test an app using webdriverio and chrome. But the app does not display anything but the images and some borders (??)(see pic). I get the same behaviour also with other websites, so it is not a problem of the app under test. Everything also displays well using other browsers (e.g firefox)
how it displays in chrome browser
Update: after searching a little bit more, I think this has something to do with passing basic auth credentials in the url, because the page I am testing is password protected. I have this in the webdriverio config file:
capabilities: [{
browserName: 'chrome',
chromeOptions: {
args: ['--disable-blink-features=BlockCredentialedSubresources']
}
}]
I am also using selenium-standalone as a service, version 0.0.10, webdriverio version 4.13.1.
In my code I open the page using:
browser.url("https://user:password#mywebsite.com/kontakt/");

Pass commandline argument to browser with Protractor

I'm trying to get PhantomJS working with Protractor. I'm currently having an issue with Phantom, but not Chrome, when my code needs to reach a backend endpoint which is kept on a separate server. As such, I would like to test it with the --ignore-ssl-errors option.
Unfortunately, the example config file provided in the Protractor documentation doesn't seem to list any way to pass arguments to the browser. Is this possible?
It turns out the answer was in a closed Protractor issue: https://github.com/angular/protractor/issues/150
You CAN pass arguments to the browser with the phantomjs.cli.args property, which takes an array of arguments. Just add it to the capabilities property in your configuration, in he same location where you specify the browserName:
capabilities: {
browserName: 'phantomjs',
'phantomjs.binary.path': require('phantomjs').path,
'phantomjs.cli.args': ['--web-security=false', '--ignore-ssl-errors=true', '--webdriver-loglevel=DEBUG'],
}