Things That Can Be Done With JavaScript & Things That Can’t Be!
Things You Can Do With JavaScript
- Access and modify all the content visible on the web page such as text, images, videos or any other kind of private data.
- Access the cookies sent by the web server.
- Make request to other servers for data capturing.
- Accessing files stored in your local system other than those uploaded on a web page.
- Accessing data from other web pages open in other tabs or on different browsers.
- Accessing and controlling the hardware capabilities of your system.
- Accessing any kind of stuff related to extensions and plugins which have been installed.
Why Would A User Visit Your Website With JavaScript Disabled?
Well, by disabling JavaScript we aim to achieve an interrupted user-experience of a website’s content. Doing so eliminates of the pop-ups, advertisements, warnings etc.Let us take a scenario to understand this better.
Well, he may feel disappointed with the overall experience of the website. And such pop-ups are quite common to encounter on any website over the internet. Which is why, Mike made sure to disable the JavaScript to ensure he doesn’t encounter more pop-ups, alerts, warnings, advertisements etc. from your website.
However, it depends entirely on how well you want your business to look like, more importantly to how many. As a best practice, it would be in the best interest to test your website with JavaScript disabled. The best part is that you don’t need to install any plugin or any other third party application in order to disable JavaScript, you have this option in your browser preferences itself. In further sections, I will show you how you can test with JavaScript disabled. However, before we do that, there are some other reasons for you to consider disabling JavaScript as you test your website.
Why Testing With JavaScript Disabled Should Be A Part Of Your QA Checklist?
As a conclusion to this, you would get your testing results in every short period of time without any chances of getting your test flow disturbed because of any third party resources.
Ease of accessibility: Many end users don’t want any kind of advertisements or pop-ups while accessing any website since this kind of stuff makes them distracted from their desirable content. So, many times these kinds of JavaScript resources are closed by the end users while accessing a particular website. This force a website owner to test their website after disabling JavaScript to verify that their users are getting easy accessibility to their website.
Also, keep in mind that some websites are fully dependent on JavaScript to make their UI more interactive, testing of such web applications after disabling JavaScript would not make any sense, than it would be better if you go for headless browser testing.
Cross Browser Compatibility: Common cross browser compatibility issues for JavaScript can be noticed such as:
- Browser JavaScript Interpreter is not able to parse and execute JavaScript code.
- New JavaScript features such as ECMAScript6 / ECMAScript Next and modern Web API fails to work in older browser versions.
Hence, it becomes necessary now to test a web application for such end users who prefer accessing websites without JavaScript.
Now, we will look into the process of disabling JavaScript for website testing.
How To Disable JavaScript For Manual Testing
- Launch a webpage for which you need to disable JavaScript.
- Right click on a page and direct to Inspect Elements.
- Once you get the developer tools open, then press CTRL+SHIFT+P.
- Type “Disable JavaScript” and click on the first option that says debugger.
- Launch a browser and enter “about:config” in URL address bar
- Click on “I accept the risk!” to see the configurations
- Enter “javascript.enabled” in search field
- Double click on “javascript.enabled” available entry to set boolean value as false
How To Disable JavaScript For Automation Testing with Selenium
Code To Run Automation Testing with Selenium In Mozilla Firefox
package DemoAutomation;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
public class JSdisableFirefox {
//Disabling JS in Firefox
@Test()
public void Firefox_javascript_disable() throws InterruptedException {
System.setProperty("webdriver.firefox.driver", "C:\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.addPreference("javascript.enabled", false);
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com/imghp");
driver.findElement(By.name("q")).sendKeys("flowers");
driver.findElement(By.className("Tg7LZd")).click();
Thread.sleep(5000);
driver.quit();
}
}
package DemoAutomation;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class JSdisableChrome {
//Disabling JS in Chrome
@Test()
public void Chrome_javascript_disable() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Lenovo-I7\\Desktop\\Selenium\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.managed_default_content_settings.javascript", 2);
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com/imghp");
driver.findElement(By.name("q")).sendKeys("flowers");
driver.findElement(By.className("Tg7LZd")).click();
Thread.sleep(5000);
driver.quit();
}
}