/*
Copyright 2012 Selenium committers
Copyright 2012 Software Freedom Conservancy

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 com.thoughtworks.selenium.corebased;

import com.thoughtworks.selenium.InternalSelenseTestBase;

import org.junit.Test;
import org.openqa.selenium.internal.WrapsDriver;

public class TestType extends InternalSelenseTestBase {
  @Test
  public void testType() throws Exception {
    selenium.open("../tests/html/test_type_page1.html");
    verifyEquals(selenium.getValue("username"), "");
    selenium.shiftKeyDown();
    selenium.type("username", "x");
    verifyEquals(selenium.getValue("username"), "X");
    selenium.shiftKeyUp();
    selenium.type("username", "TestUserWithLongName");
    verifyEquals(selenium.getValue("username"), "TestUserWi");
    selenium.type("username", "TestUser");
    verifyEquals(selenium.getValue("username"), "TestUser");
    verifyEquals(selenium.getValue("password"), "");
    selenium.type("password", "testUserPasswordIsVeryLong");
    verifyEquals(selenium.getValue("password"), "testUserPasswordIsVe");
    selenium.type("password", "testUserPassword");
    verifyEquals(selenium.getValue("password"), "testUserPassword");
    if (isAbleToUpdateFileElements()) {
      selenium.type("file", "/test/file");
      selenium.click("submitButton");
      selenium.waitForPageToLoad("30000");
      verifyTrue(selenium.isTextPresent("Welcome, TestUser!"));
    }
  }

  private boolean isAbleToUpdateFileElements() {
    String browser = System.getProperty("selenium.browser", runtimeBrowserString());

    return selenium instanceof WrapsDriver ||
           "*firefox".equals(browser) || "*firefoxchrome".equals(browser);
  }
}

@@ -652,16 +652,92 @@
 based;%0A%0A
+import com.google.common.base.Charsets;%0Aimport com.google.common.io.Files;%0A%0A
 import c
@@ -860,16 +860,38 @@
 river;%0A%0A
+import java.io.File;%0A%0A
 public c
@@ -1825,42 +1825,213 @@
     
-selenium.type(%22file%22, %22/test/file%22
+File tempFile = File.createTempFile(%22example%22, %22upload%22);%0A      tempFile.deleteOnExit();%0A      Files.write(%22I like cheese%22, tempFile, Charsets.UTF_8);%0A      selenium.type(%22file%22, tempFile.getAbsolutePath()
 );%0A 

Use a real file in our tests