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);
}
}
なぜ2つのドライバを作成していますか? 'FirefoxDriver'と' WiniumDriver'ですか?セレンでは一般に1人のドライバーがいます。あなたが 'input'を見つけたらそれをクリックしません。エレメントにファイルパスを送るために 'sendKeys()'を使うだけです。 Seleniumがファイルをアップロードします。 – RemcoW
私はsendKeys()を使用してファイルをアップロードできますが、一部のアプリケーションでは動作しません。 Winiumを使用する必要がある場合は、最初にドライバを起動する必要があります。 –