2016-07-01 16 views
0

私は、AutoIt、Robot Class、その他の方法で、ブラウザにファイルをアップロードすることができます。Winiumを使用してWebブラウザにファイルをアップロードするには?

私はWiniumに導入されました。それと同じテストケースを作りたい、それを使ってブラウザにファイルをアップロードしたいのですが、Webドライバとwiniumドライバを切り替えるにはどうすればよいか分かりませんでした。私はこのトリックのために多くのことを探索していますが、まだsolution.Iが私のために働いていた私のスクリプトを共有しています見つけている場合は任意の結果に

package testUtilities; 

import java.io.File; 
import java.io.IOException; 
import java.net.MalformedURLException; 
import java.net.URL; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.winium.WiniumDriver; 
import org.testng.annotations.BeforeClass; 
import org.testng.annotations.Test; 

public class WiniumWeb 
{ 
    WebDriver driver; 

    @BeforeClass 
    public void setUp() throws IOException 
    { 
     driver = new FirefoxDriver(); 
     driver.navigate().to("http://the-internet.herokuapp.com/upload"); 
     driver.findElement(By.id("file-upload")).click(); 

     String WiniumEXEpath = System.getProperty("user.dir") + "\\Resources\\Winium.Desktop.Driver.exe"; 
     File file = new File(WiniumEXEpath); 
     if (! file.exists()) 
     { 
      throw new IllegalArgumentException("The file " + WiniumEXEpath + " does not exist"); 
     } 
     Runtime.getRuntime().exec(file.getAbsolutePath()); 



     try 
     { 
      driver = new WiniumDriver(new URL("http://localhost:9999"), null); 
     } catch (MalformedURLException e) 
     { 
      e.printStackTrace(); 
     } 

    } 

    @Test 
    public void testNotePade() throws InterruptedException 
    { 
     String file = System.getProperty("user.dir") + "\\Resources\\TestData.csv"; 
     WebElement window = driver.findElement(By.className("File Upload")); 
     window.findElement(By.className("#32770")).sendKeys(file); 

     Thread.sleep(2000); 
    } 


} 
+0

なぜ2つのドライバを作成していますか? 'FirefoxDriver'と' WiniumDriver'ですか?セレンでは一般に1人のドライバーがいます。あなたが 'input'を見つけたらそれをクリックしません。エレメントにファイルパスを送るために 'sendKeys()'を使うだけです。 Seleniumがファイルをアップロードします。 – RemcoW

+0

私はsendKeys()を使用してファイルをアップロードできますが、一部のアプリケーションでは動作しません。 Winiumを使用する必要がある場合は、最初にドライバを起動する必要があります。 –

答えて

0

を見つけることができなかったので、助けてください。

public class FileUpload extends BaseClass { 
static WiniumDriver d; 

@BeforeClass 
public void setUp() throws IOException { 
    DesktopOptions options = new DesktopOptions(); 
    options.setApplicationPath("C:\\Windows\\System32\\openfiles.exe"); 
    LaunchLocalBrowser("chrome","http://the-internet.herokuapp.com/upload");//use your own code to launch browser 
    driver.findElement(By.id("file-upload")).click(); 

    String WiniumEXEpath = System.getProperty("user.dir") + "\\lib\\Winium.Desktop.Driver.exe"; 
    File file = new File(WiniumEXEpath); 
    if (! file.exists()) { 
     throw new IllegalArgumentException("The file " + WiniumEXEpath + " does not exist"); 
    } 
    Runtime.getRuntime().exec(file.getAbsolutePath()); 
    try { 
     d = new WiniumDriver(new URL("http://localhost:9999"),options); 
    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } 
} 

@Test 
public void testNotePade() throws InterruptedException { 
    String file = System.getProperty("user.dir") + "\\lib\\Testdata.txt"; 
    d.findElementByName("File name:").sendKeys(file); 
    d.findElementByXPath("//*[@Name='Cancel']//preceding-sibling::*[@Name='Open']").click(); 
    driver.findElement(By.id("file-submit")).click(); 
} 
} 
関連する問題