|
| 1 | +// Licensed to the Software Freedom Conservancy (SFC) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The SFC licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | + |
| 19 | +package com.thoughtworks.selenium.corebased; |
| 20 | + |
| 21 | +import com.google.common.base.Charsets; |
| 22 | +import com.google.common.io.Files; |
| 23 | + |
| 24 | +import com.thoughtworks.selenium.InternalSelenseTestBase; |
| 25 | + |
| 26 | +import org.junit.Before; |
| 27 | +import org.junit.Test; |
| 28 | + |
| 29 | +import java.io.File; |
| 30 | +import java.io.IOException; |
| 31 | + |
| 32 | +public class TestAttachFile extends InternalSelenseTestBase { |
| 33 | + |
| 34 | + private static final String LOREM_IPSUM_TEXT = "lorem ipsum dolor sit amet"; |
| 35 | + private static final String FILE_HTML = "<div>" + LOREM_IPSUM_TEXT + "</div>"; |
| 36 | + |
| 37 | + private File testFile; |
| 38 | + |
| 39 | + @Before |
| 40 | + public void setUp() throws Exception { |
| 41 | + testFile = createTmpFile(FILE_HTML); |
| 42 | + } |
| 43 | + |
| 44 | + private File createTmpFile(String content) throws IOException { |
| 45 | + File f = File.createTempFile("webdriver", "tmp"); |
| 46 | + f.deleteOnExit(); |
| 47 | + Files.write(content, f, Charsets.UTF_8); |
| 48 | + return f; |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void testAttachFile() throws Exception { |
| 53 | + selenium.open("/common/upload.html"); |
| 54 | + selenium.attachFile("upload", testFile.toURI().toURL().toString()); |
| 55 | + selenium.click("go"); |
| 56 | + selenium.waitForPageToLoad("30000"); |
| 57 | + selenium.selectFrame("upload_target"); |
| 58 | + assertEquals(selenium.getText("//body"), LOREM_IPSUM_TEXT); |
| 59 | + } |
| 60 | +} |
0 commit comments