package com.sdl.bootstrap.button;

import com.sdl.selenium.web.WebDriverConfig;
import com.sdl.selenium.web.WebLocator;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;

public class UploadFile extends WebLocator implements Upload {

    public UploadFile() {
        setClassName("UploadFile");
        setClasses("fileupload");
        setTag("div");
    }

    /**
     * @param container parent
     */
    public UploadFile(WebLocator container) {
        this();
        setContainer(container);
    }

    public UploadFile(WebLocator container, String label) {
        this(container);
        setLabel(label);
    }

    /**
     * Upload file with AutoIT.
     * Use only this: button.upload("Browse", "C:\\upload.exe", "C:\\text.txt");
     *
     * @param text button text
     * @param filePath e.g. "C:\\upload.exe", "C:\\text.txt"
     */
    public boolean upload(String text, String ...filePath) {
            WebLocator upload = new WebLocator(this).setTag("span").setClasses("fileupload-new").setText(text);
            return upload(upload, filePath);
    }

    public void change(String ...filePath) {
        change("Change", filePath);
    }

    public boolean change(String text, String ...filePath) {
        WebLocator upload = new WebLocator(this).setTag("span").setClasses("fileupload-exists").setText(text);
        return upload(upload, filePath);
    }

    /**
     * Upload file with AutoIT.
     * Use only this: button.upload("C:\\upload.exe", "C:\\text.txt");
     *
     * @param filePath new String[] {"C:\\upload.exe", "C:\\text.txt"}
     */
    @Override
    public boolean upload(String ...filePath) {
        WebLocator uploadButton = new WebLocator(this).setTag("span").setClasses("fileupload-new").setElPathSuffix("count(.//i[@class='icon-folder-open']) > 0");
        return upload(uploadButton, filePath);
    }

    public boolean reUpload(String ...filePath) {
        WebLocator uploadButton = new WebLocator(this).setTag("span").setClasses("fileupload-exists").setElPathSuffix("count(.//i[@class='icon-refresh']) > 0");
        return upload(uploadButton, filePath);
    }

    public boolean removeFile() {
        WebLocator removeButton = new WebLocator(this).setTag("a").setClasses("fileupload-exists").setElPathSuffix("count(.//i[@class='icon-trash']) > 0");
        return removeButton.clickAt();
    }

    public String uploadedNameFile() {
        WebLocator upload = new WebLocator(this).setTag("span").setClasses("fileupload-preview");
        return upload.getHtmlText();
    }

    public boolean upload(WebLocator el, String ...filePath) {
        browse(el);
        return RunExe.getInstance().upload(filePath);
    }

    private void browse(WebLocator el) {
        WebDriver driver = WebDriverConfig.getDriver();
        driver.switchTo().window(driver.getWindowHandle());
        el.focus();
        Actions builder = new Actions(driver);
        builder.moveToElement(el.currentElement).build().perform();
        builder.click().build().perform();
        driver.switchTo().defaultContent();
    }
}
@@ -113,24 +113,57 @@
 ebLocator;%0D%0A
+import org.apache.log4j.Logger;%0D%0A
 import org.o
@@ -304,16 +304,94 @@
 pload %7B%0D
+%0A    private static final Logger LOGGER = Logger.getLogger(UploadFile.class);%0D
 %0A%0D%0A    p
@@ -947,16 +947,20 @@
 am text 
+    
 button t
@@ -1072,36 +1072,36 @@
 ing text, String
- 
 ...
+ 
 filePath) %7B%0D%0A   
@@ -1093,28 +1093,24 @@
 ilePath) %7B%0D%0A
-    
         WebL
@@ -1210,28 +1210,24 @@
 );%0D%0A        
- 
-   
 return uploa
@@ -1282,28 +1282,28 @@
 hange(String
- 
 ...
+ 
 filePath) %7B%0D
@@ -1386,36 +1386,36 @@
 ing text, String
- 
 ...
+ 
 filePath) %7B%0D%0A   
@@ -1816,36 +1816,36 @@
 an upload(String
- 
 ...
+ 
 filePath) %7B%0D%0A   
@@ -2091,28 +2091,28 @@
 pload(String
- 
 ...
+ 
 filePath) %7B%0D
@@ -2809,12 +2809,12 @@
 ring
- 
 ...
+ 
 file
@@ -3197,32 +3197,77 @@
 d().perform();%0D%0A
+        LOGGER.debug(%22El=%22 + el.getPath());%0D%0A
         builder.

add log in UploadFile