簡體   English   中英

通過字符串數組進行迭代-傳遞文件路徑Selenium

[英]Issue iterating through string array - passing filepath Selenium

我創建了一種方法(在搜索此站點之后),將文件路徑輸入到Windows文件管理器中。 這很好用,但是我想擴展測試用例以遍歷一系列文件位置,然后將測試文件傳遞給Web應用程序以測試它們是否得到正確處理。

我遇到了一個問題,在第二遍(我有2個測試文件)中,Windows處理程序方法不想輸入文件名。 有人可以掃描我的代碼以指向正確的方向。

這是Windows文件管理器方法:

public class WindowsFileSystemHandler {
String filepath;

public void enterfilepath(String pfilepath) throws Exception{

    filepath = pfilepath;

    StringSelection ss = new StringSelection(filepath);
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,   null);
    Robot robot = new Robot();
    //robot.keyPress(KeyEvent.VK_ENTER);
    //robot.keyRelease(KeyEvent.VK_ENTER);
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
    Thread.sleep(2000);
}

}

這是測試:

    WindowsFileSystemHandler file = new WindowsFileSystemHandler();
        String[] fileloc = {"d:\\JW\\testfiles\\scribbles.txt", "d:\\JW\\testfiles\\earth_large_file_size.jpg"} ;
        for(int i =0 ; i<2; i++){

        Thread.sleep(2000);

        try {
            //WindowsFileSystemHandler file = new WindowsFileSystemHandler();
                    file.enterfilepath(fileloc[i]);
                    System.out.println(fileloc[i]);
                    System.out.println(i);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        String testfiletype = driver.findElement(By.xpath(".//*[@id='SFI_control']/div[2]/div[2]")).getText();
        System.out.println(testfiletype);
        ProfilePage.is_file_validation_successful(testfiletype);
    }//end of for loop

順便說一句,控制台輸出如下:

d:\JW\testfiles\scribbles.txt
0
Invalid file type.
 true
 Test to see if system correctly rejects invalid file type was successful
d:\JW\testfiles\earth_large_file_size.jpg
1
Invalid file type.
 true
Test to see if system correctly rejects invalid file type was successful

我可能缺少一些愚蠢的東西。

我知道了我的問題。 基本上,我提出了以下聲明:

driver.findElement(By.xpath(".//*[starts-with(@id, 'd2l_1_3_')]")).click();

進入for循環,這解決了我的問題。 愚蠢的錯誤。

有趣的是,我在使用這種方法的測試系統中發現了一個錯誤,因為在每次上傳文件后都沒有清除以前的錯誤消息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM