public class

EnableJavascriptAction

extends java.lang.Object

implements ViewAction

 java.lang.Object

↳androidx.test.espresso.web.action.EnableJavascriptAction

Gradle dependencies

compile group: 'androidx.test.espresso', name: 'espresso-web', version: '3.6.1'

  • groupId: androidx.test.espresso
  • artifactId: espresso-web
  • version: 3.6.1

Artifact androidx.test.espresso:espresso-web:3.6.1 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test.espresso:espresso-web com.android.support.test.espresso:espresso-web

Androidx class mapping:

androidx.test.espresso.web.action.EnableJavascriptAction android.support.test.espresso.web.action.EnableJavascriptAction

Overview

Forcibly enables Javascript on a WebView.

This has side-effects callers should be aware of:

  • On Jellybean and below - the WebView will be reloaded.
  • Javascript will be enabled for the rest of the view's lifetime

Summary

Constructors
publicEnableJavascriptAction()

Methods
public <any>getConstraints()

public java.lang.StringgetDescription()

public voidperform(UiController uiController, View view)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public EnableJavascriptAction()

Methods

public <any> getConstraints()

public java.lang.String getDescription()

public void perform(UiController uiController, View view)

Source

/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.test.espresso.web.action;

import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom;

import android.view.View;
import android.webkit.WebView;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import org.hamcrest.Matcher;

/**
 * Forcibly enables Javascript on a WebView.
 *
 * <p>This has side-effects callers should be aware of:
 *
 * <ul>
 *   <li>On Jellybean and below - the WebView will be reloaded.
 *   <li>Javascript will be enabled for the rest of the view's lifetime
 * </ul>
 */
public class EnableJavascriptAction implements ViewAction {

  @Override
  public Matcher<View> getConstraints() {
    return isAssignableFrom(WebView.class);
  }

  @Override
  public String getDescription() {
    return "Forcibly enable javascript.";
  }

  @Override
  public void perform(UiController uiController, View view) {
    WebView webView = (WebView) view;
    if (!webView.getSettings().getJavaScriptEnabled()) {
      webView.getSettings().setJavaScriptEnabled(true);
    }
  }
}