tags:

views:

27

answers:

1

While using FirefoxDriver to write tests,

I discovered loading of pages are really slow because of javascript and css being executed. IS there anyway to disable this ? possible to even install Noscript plugin to profile ?

additionally, sendKeys(), actually types out the text. however, this is quite slow for long text, anyway to instantly type all the string int othe input box ?

A: 

You can disable javaScript in FirefoxProfile:

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("javascript.enabled", false);
    WebDriver driver = new FirefoxDriver(profile);

I do not think that there's a way to disable CSS and this not what you should do - this may break your web application, and disabling JavaScript may do this too.

There's no way to set the value of the text field directly - WebDriver is designed to simulate the real user "driving" the browser - that's why there's only sendKeys.

However you can set the value of the element via JavaScript call (if you will not disable it, of course). This is faster for the long test, but this is not the emulation of the user interaction so some validations may not be triggered, so use with caution:

private void setValue(WebElement element, String value) {
        ((JavascriptExecutor)driver).executeScript("arguments[0].value = arguments[1]", element, value);
    }

and use it:

    WebElement inputField = driver.findElement(By...);
    setValue(inputField, "The long long long long long long long text......");
ZloiAdun