简体   繁体   English

在Selenium Webdriver中编写测试脚本时,未使用局部变量“ X”的值

[英]The value of the local variable 'X' is not used, while writing test script in selenium webdriver

I'm writing test script in selenium using testng annotations. 我正在使用testng注释在Selenium中编写测试脚本。 My application has separate fields to upload audios, videos, images etc. I'm using following code to upload images in the respective field. 我的应用程序具有单独的字段以上传音频,视频,图像等。我正在使用以下代码在相应的字段中上传图像。

`@Test (priority = 1)   
public void Save() throws InterruptedException
{       
WebElement element = driver.findElement(By.partialLinkText("Add Case"));
Actions action = new Actions (driver);
action.moveToElement(element); 
action.click().build().perform(); //Click on 'Add Case' button 
driver.findElement(By.id("name")).sendKeys("Selenium 7"); 

//upload images
File fisheye_tier1 = new File("*path where images are saved in local machine*");
File[] fisheyeimages = fisheye_tier1.listFiles();
String fishList = "";
for(int i = 0; i < fisheyeimages.length;i++){
fishList += (i != 0 ?"\n":"") + fisheyeimages[i].getAbsolutePath();
}
driver.findElement(By.id("fileupload")).sendKeys(fishList);
Thread.sleep(3000);
driver.findElement(By.id("btnSave")).click(); 
Thread.sleep(5000);`

This code works as expected for me and upload all images. 此代码对我来说可以正常工作并上传所有图像。 But when I use similar concept to upload videos, my test fails. 但是,当我使用类似的概念上传视频时,我的测试失败了。 The script to upload videos is as follows: 上传视频的脚本如下:

`@Test (priority = 2)
public void Submit() throws InterruptedException
{
//upload videos
File evidence_tier1 = new File("*path where videos are saved in local machine*");
File[] evidenceimages = evidence_tier1.listFiles();
String eviList = "";
for(int i = 0; i < evidenceimages.length;i++){
eviList += (i != 0 ?"\n":"") + evidenceimages[i].getAbsolutePath();
}
driver.findElement(By.id("fileupload1")).sendKeys("eviList");
Thread.sleep(3000);

In eclipse it shows a yellow line below eviList with error The value of the local variable eviList is not used . 在Eclipse中,它在eviList显示一条黄线, eviList带有错误The value of the local variable eviList is not used Seems its a leakage but their is no error when I upload images with same script. 似乎是一个泄漏,但是当我使用相同脚本上传图像时它们没有错误。

sendKeys(“ eviList”)-您需要传递变量而不是字符串-sendKeys(eviList)

You are passing String "eviList" instead of variable eviList 您正在传递字符串“ eviList”,而不是变量eviList

Update your code as below. 如下更新代码。

driver.findElement(By.id("fileupload1")).sendKeys(eviList);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM