Skip to content

Commit

Permalink
webdriven: Fixing attachFile command and adding a test for this comma…
Browse files Browse the repository at this point in the history
…nd (it is not included in the suite because it should be run in local env only and can't be run on CI server at the moment)
  • Loading branch information
barancev committed Jun 2, 2015
1 parent 3a7e29e commit 0e39157
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ private File downloadFile(String name) {
URL url = getUrl(name);

File dir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("attachFile", "dir");
File outputTo = new File(dir, url.getFile());
if (!outputTo.getParentFile().mkdirs()) {
throw new SeleniumException("Cannot create file for upload: " + outputTo);
}
File outputTo = new File(dir, new File(url.getFile()).getName());

FileOutputStream fos = null;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you 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.google.common.base.Charsets;
import com.google.common.io.Files;

import com.thoughtworks.selenium.InternalSelenseTestBase;

import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

public class TestAttachFile extends InternalSelenseTestBase {

private static final String LOREM_IPSUM_TEXT = "lorem ipsum dolor sit amet";
private static final String FILE_HTML = "<div>" + LOREM_IPSUM_TEXT + "</div>";

private File testFile;

@Before
public void setUp() throws Exception {
testFile = createTmpFile(FILE_HTML);
}

private File createTmpFile(String content) throws IOException {
File f = File.createTempFile("webdriver", "tmp");
f.deleteOnExit();
Files.write(content, f, Charsets.UTF_8);
return f;
}

@Test
public void testAttachFile() throws Exception {
selenium.open("/common/upload.html");
selenium.attachFile("upload", testFile.toURI().toURL().toString());
selenium.click("go");
selenium.waitForPageToLoad("30000");
selenium.selectFrame("upload_target");
assertEquals(selenium.getText("//body"), LOREM_IPSUM_TEXT);
}
}

0 comments on commit 0e39157

Please sign in to comment.