2014-03-27 70 views
0

使用Selenium Webdriver和使用Java。我收到提示为该系统找不到指定的路径系统找不到在java中指定的路径

代码:

package test; 
import java.io.BufferedReader; 
import java.io.FileInputStream; 
import java.io.FileReader; 
import java.util.ArrayList; 
import java.util.List; 
import java.util.Properties; 
import java.util.ResourceBundle; 
import org.openqa.selenium.By; 
import org.openqa.selenium.JavascriptExecutor; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.interactions.Actions; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.Select; 
import org.openqa.selenium.support.ui.WebDriverWait; 
import org.testng.Assert; 
import org.testng.Reporter; 
import org.testng.annotations.AfterTest; 
import org.testng.annotations.BeforeTest; 
import org.testng.annotations.Test; 
import org.apache.log4j.Logger; 
import org.apache.log4j.xml.DOMConfigurator; 
import com.thoughtworks.selenium.DefaultSelenium; 
import com.thoughtworks.selenium.Selenium; 
public class OEPR_DefaultTab{ 
private static Logger Log = Logger.getLogger(OEPR_DefaultTab.class.getName()); 
private WebDriver driver; 
private StringBuffer verificationErrors = new StringBuffer(); 
Properties p= new Properties(); 
public Selenium selenium; 

@BeforeTest 
public void Login() throws Exception { 
driver = new FirefoxDriver(); 
try { 
     p.load(new FileInputStream("C:/Login.txt")); 
    } catch (Exception e) { 
     e.getMessage(); 
    } 
String url=p.getProperty("url"); 
DOMConfigurator.configure("src/log4j.xml"); 
Log.info("______________________________________________________________"); 
Log.info("Initializing Selenium..."); 

selenium = new DefaultSelenium("localhost", 4444, "*firefox",url); 
Thread.sleep(5000); 
Log.info("Selenium instance started"); 


try { 
     p.load(new FileInputStream("C:/Login.txt")); 
    } catch (Exception e) { 
     e.getMessage(); 
    } 
Log.info("Accessing Stored uid,pwd from the stored text file"); 
String uid=p.getProperty("loginUsername"); 
String pwd=p.getProperty("loginPassword"); 
Log.info("Retrieved uid pwd from the text file"); 
try 
{ 
driver.get("https://10.4.16.159/login"); 
} 
catch(Exception e) 
{ 
    Reporter.log("network server is slow..check internet connection"); 
    Log.info("Unable to open the website"); 
    throw new Error("network server is slow..check internet connection"); 
} 
    performLogin(uid,pwd); 
} 

public void performLogin(String uid,String pwd) throws Exception 
{ 
Log.info("Sign in to the OneReports website"); 
Thread.sleep(5000); 
Log.info("Enter Username"); 
driver.findElement(By.id("loginUsername")).sendKeys(uid); 
Log.info("Enter Password"); 
driver.findElement(By.id("loginPassword")).sendKeys(pwd); 
//submit 
Log.info("Submitting login details"); 
waitforElement(driver,120 , "//*[@id='submit']"); 
driver.findElement(By.id("submit")).submit(); 
Thread.sleep(6000); 
Actions actions = new Actions(driver); 

Log.info("Clicking on Reports link"); 
if(existsElement("reports")==true){ 

     WebElement menuHoverLink = driver.findElement(By.id("reports")); 
     actions.moveToElement(menuHoverLink).perform(); 
     Thread.sleep(6000); 
     } 
     else{ 
      Log.info("element not present"); 
      System.out.println("element not present -- so it entered the else loop"); 

    } 
Log.info("Clicking on Extranet link"); 
if(existsElement("extranet")==true){ 

     WebElement menuHoverLink = driver.findElement(By.id("extranet")); 
     actions.moveToElement(menuHoverLink).perform(); 
     Thread.sleep(6000); 
     } 
     else{ 
      Log.info("element not present"); 
      System.out.println("element not present -- so it entered the else loop"); 

    } 
Log.info("Clicking on PR link"); 
if(existsElement("ext-pr")==true){ 

     WebElement menuHoverLink = driver.findElement(By.id("ext-pr")); 
     actions.moveToElement(menuHoverLink).perform(); 
     Thread.sleep(6000); 
     } 
     else{ 
      Log.info("element not present"); 
      System.out.println("element not present -- so it entered the else loop"); 


    } 
Log.info("Clicking on Overview and Evolution PR link"); 
if(existsElement("ext-pr-backlog-evolution")==true){ 

    JavascriptExecutor executor = (JavascriptExecutor)driver; 
    executor.executeScript("arguments[0].click();", driver.findElement(By.id("ext-pr-backlog-evolution"))); 
    //executor.executeScript("document.getElementById('ext-pr-backlog-evolution').style.display='block';"); 
    //driver.findElement(By.id("ext-pr-backlog-evolution")).click(); 
    // WebElement menuHoverLink = driver.findElement(By.id("ext-pr-backlog-evolution")); 
     //actions.moveToElement(menuHoverLink).perform(); 

     Thread.sleep(6000); 
     } 
     else{ 
      Log.info("element not present"); 
      System.out.println("element not present -- so it entered the else loop"); 
    } 
} 

//Filter selection-1 


@Test() 
public void Filterselection_1() throws Exception{ 

BufferedReader in = new BufferedReader(new FileReader("C:/FilerSection/visualization.txt"));\\ Here i'm getting error 
String line; 
line = in.readLine(); 
in.close(); 

String[] expectedDropDownItemsInArray = line.split("=")[1].split(","); 

// Create expected list :: This will contain expected drop-down values 

ArrayList<String> expectedDropDownItems = new ArrayList<String>(); 
for(int i=0; i<expectedDropDownItemsInArray.length; i++) 
    expectedDropDownItems.add(expectedDropDownItemsInArray[i]); 

// Create a webelement for the drop-down 
WebElement visualizationDropDownElement = driver.findElement(By.id("visualizationId")); 

// Instantiate Select class with the drop-down webelement 
Select visualizationDropDown = new Select(visualizationDropDownElement); 

// Retrieve all drop-down values and store in actual list 
List<WebElement> valuesUnderVisualizationDropDown = visualizationDropDown.getOptions(); 

ArrayList<String> actualDropDownItems = new ArrayList<String>(); 

for(WebElement value : valuesUnderVisualizationDropDown){ 
    actualDropDownItems.add(value.getText()); 
} 

// Compare expected and actual list 
for (int i = 0; i < actualDropDownItems.size(); i++) { 
    if (!expectedDropDownItems.get(i).equals(actualDropDownItems.get(i))) 
    System.out.println("Drop-down values are NOT in correct order"); 
} 
} 


private boolean existsElement(String id) { 
try { 
    driver.findElement(By.id(id)); 
} catch (Exception e) { 
    System.out.println("id is not present "); 
    return false; 
} 

return true; 
} 


private void waitforElement(WebDriver driver2, int i, String string) { 
// TODO Auto-generated method stub 

} 


@AfterTest 

public void tearDown() throws Exception { 
Log.info("Stopping Selenium..."); 
Log.info("______________________________________________________________"); 
driver.quit(); 
String verificationErrorString = verificationErrors.toString(); 
if (!"".equals(verificationErrorString)) { 
    Assert.fail(verificationErrorString); 
} 
} 
}  

请检查代码给我一些解决方案。
存在于How to compare the drop down options is matching with the UI options in Selenium WebDriver? 中的场景对于这个场景,我试图编写脚本。请检查链接。

+0

对不起,说的很明显,但如果你在windows上,那么你应该指定文件路径为'C:// FilerSection // visualization.txt',即转义'/'符号。 – olyv

回答

0

如果这是您看到的确切文字,这通常不是代码问题 - 这意味着您需要更新您的PATH环境变量与安装了Java的目录。

+0

我给出了相同的路径try {p.load(new FileInputStream(“C:/FilerSection/visualization.txt”)); //新增FileInputStream(“C:/FilerSection/Dropdown.txt”)); } catch(Exception e){e.getMessage(); Log.info(“从存储的文本文件中访问存储的ID”); String id = p.getProperty(“visualizationId”); Log.info(“从文本文件中检索到的ID”); performLogin1(ID); – Amirdha

+0

它正在加载属性文件。我在这一行中得到的问题BufferedReader in = new BufferedReader(new FileReader(“C:/FilerSection/visualization.txt”)); – Amirdha

+0

关于Stackexchange的疯狂之处在于,您需要更多信誉才能评论而不是回答。暂时我必须提供答案,直到我有足够的声望评论:)。在任何情况下,从我看到的其他帖子来看,这个错误消息意味着PATH环境变量是错误的。但是,它确实出现了更多的信息,说明其他事情正在发生。 – BobDoolittle

0

更换

BufferedReader in = new BufferedReader(new FileReader("C:/FilerSection/visualization.txt")); 

BufferedReader in = new BufferedReader(new FileReader("C:\\FilerSection\\visualization.txt")); 

这应该帮助。

+0

@ user11111:让我们知道您是否有正确的答案或需要更多信息。 –

相关问题