I'm building a webapp which falls back on a <noscript>
tag if Javascript is disabled. I'd like to validate that that tag shows, but I'm unsure how to do that with any of the frameworks I have, or any framework in general.
The app in question by default shows the following when Javascript is disabled:
<div>
<noscript>
<h1>Javascript Disabled</h1>
Use this page to show content when Javascript has been disabled
</noscript>
</div>
The app replaces the above with the following when the script is loaded:
<div>
Hello World
</div>
Right now for tests I'm using NightmareJS and Testem with jasmine. I don't have to be using those, but I'd like to still use Javascript if possible.
I'm completely stumped here and have no idea where I would even start - all the StackOverflow questions seem to be about how to USE <noscript>
, and not validating it in an end-to-end or unit test (in an automated manner).
NightmareJS uses Electron under the hood to run the tests which doesn't seem to support passing a flag that disables Javascript, although I have to warn you that I didn't dig around that much.
... I'm using NightmareJS and Testem with jasmine. I don't have to be using those, but I'd like to still use javascript if possible.
Another solution is to use NightwatchJS instead of NightmareJS, which is a testing framework that uses ChromeDriver to drive the tests which allows disabling JS by passing prefs to Chromium.
I've written a sample project as a very basic example on how to run NightwatchJS tests with JS disabled.
The project uses the following configuration to disable JS:
nightwatch.json
{
"test_settings" : {
"default" : {
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions" : {
"prefs" : {
"profile.managed_default_content_settings.javascript": 2
}
}
}
}
}
}
In the above configuration, it's this particular line that is passed to Chromium which hints that we want JS disabled when NighwatchJS runs the tests:
"profile.managed_default_content_settings.javascript": 2
That being said, I'd suggest you dig a bit more thoroughly in Nightmare's documentation/issues to check if you can pass the above pref through NightmareJS instead of rewriting all your tests in NightwatchJS for this little quirk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With