<commit_before>package nl.hsac.fitnesse.fixture.slim.web;

import fitnesse.slim.fixtureInteraction.FixtureInteraction;
import nl.hsac.fitnesse.fixture.util.NgClientSideScripts;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Browser Test targeted to test AngularJs apps.
 */
public class NgBrowserTest extends BrowserTest {
    private final static Set<String> METHODS_NO_WAIT;
    private String angularRoot = null;

    static {
        METHODS_NO_WAIT = new HashSet<String>(Arrays.asList(
                "open",
                "takeScreenshot",
                "openInNewTab",
                "ensureActiveTabIsNotClosed",
                "currentTabIndex",
                "tabCount",
                "ensureOnlyOneTab",
                "closeTab",
                "setAngularRoot",
                "switchToNextTab",
                "switchToPreviousTab",
                "waitForAngularRequestsToFinish",
                "secondsBeforeTimeout",
                "waitForPage",
                "waitForTagWithText",
                "waitForClassWithText",
                "waitForClass",
                "waitSeconds",
                "waitMilliseconds",
                "waitMilliSecondAfterScroll",
                "screenshotBaseDirectory",
                "screenshotShowHeight",
                "setBrowserWidth",
                "setBrowserHeight",
                "setBrowserSizeToBy",
                "setGlobalValueTo",
                "globalValue",
                "setAngularRoot",
                "getAngularRoot"));
        Method[] allMethods = NgBrowserTest.class.getMethods();
        List<String> allMethodNames = new ArrayList<String>(allMethods.length);
        for (Method method : allMethods) {
            allMethodNames.add(method.getName());
        }
        List<String> notFound = new ArrayList<String>(0);
        for (String methodName : METHODS_NO_WAIT) {
            if (!allMethodNames.contains(methodName)) {
                notFound.add(methodName);
            } else {
                allMethodNames.remove(methodName);
            }
        }
        if (!notFound.isEmpty()) {
            throw new RuntimeException("Unable to locate methods to be skipped: " + notFound);
        }
    }

    @Override
    public Object aroundSlimInvoke(FixtureInteraction interaction, Method method, Object... arguments) throws InvocationTargetException, IllegalAccessException {
        String methodName = method.getName();
        if (!METHODS_NO_WAIT.contains(methodName)) {
            waitForAngularRequestsToFinish();
        }
        return super.aroundSlimInvoke(interaction, method, arguments);
    }

    @Override
    public boolean open(String address) {
        boolean result = super.open(address);
        if (result) {
            waitForAngularRequestsToFinish();
        }
        return result;
    }

    public void waitForAngularRequestsToFinish() {<commit_msg>Rename variable<commit_after>package nl.hsac.fitnesse.fixture.slim.web;

import fitnesse.slim.fixtureInteraction.FixtureInteraction;
import nl.hsac.fitnesse.fixture.util.NgClientSideScripts;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Browser Test targeted to test AngularJs apps.
 */
public class NgBrowserTest extends BrowserTest {
    private final static Set<String> METHODS_NO_WAIT;
    private String angularRoot = null;

    static {
        METHODS_NO_WAIT = new HashSet<String>(Arrays.asList(
                "open",
                "takeScreenshot",
                "openInNewTab",
                "ensureActiveTabIsNotClosed",
                "currentTabIndex",
                "tabCount",
                "ensureOnlyOneTab",
                "closeTab",
                "setAngularRoot",
                "switchToNextTab",
                "switchToPreviousTab",
                "waitForAngularRequestsToFinish",
                "secondsBeforeTimeout",
                "waitForPage",
                "waitForTagWithText",
                "waitForClassWithText",
                "waitForClass",
                "waitSeconds",
                "waitMilliseconds",
                "waitMilliSecondAfterScroll",
                "screenshotBaseDirectory",
                "screenshotShowHeight",
                "setBrowserWidth",
                "setBrowserHeight",
                "setBrowserSizeToBy",
                "setGlobalValueTo",
                "globalValue",
                "setAngularRoot",
                "getAngularRoot"));
        Method[] allMethods = NgBrowserTest.class.getMethods();
        List<String> methodsRequiringWait = new ArrayList<String>(allMethods.length);
        for (Method method : allMethods) {
            methodsRequiringWait.add(method.getName());
        }
        List<String> notFound = new ArrayList<String>(0);
        for (String methodName : METHODS_NO_WAIT) {
            if (!methodsRequiringWait.contains(methodName)) {
                notFound.add(methodName);
            } else {
                methodsRequiringWait.remove(methodName);
            }
        }
        if (!notFound.isEmpty()) {
            throw new RuntimeException("Unable to locate methods to be skipped: " + notFound);
        }
    }

    @Override
    public Object aroundSlimInvoke(FixtureInteraction interaction, Method method, Object... arguments) throws InvocationTargetException, IllegalAccessException {
        String methodName = method.getName();
        if (!METHODS_NO_WAIT.contains(methodName)) {
            waitForAngularRequestsToFinish();
        }
        return super.aroundSlimInvoke(interaction, method, arguments);
    }

    @Override
    public boolean open(String address) {
        boolean result = super.open(address);
        if (result) {
            waitForAngularRequestsToFinish();
        }
        return result;
    }

    public void waitForAngularRequestsToFinish() {
{'fraction_non_alphanumeric': 0.09122474747474747, 'fraction_numerical': 0.0003156565656565657, 'mean_word_length': 2.103330068560235, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5527638', 'n_tokens_mistral': 1707, 'n_tokens_neox': 1618, 'n_words': 307}