系统找不到java中指定的路径

时间:2014-03-27 03:39:24

标签: java selenium selenium-webdriver webdriver

使用Selenium Webdriver并使用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?中出现的情景 对于这种情况,我试图编写脚本。请检查链接。

2 个答案:

答案 0 :(得分:0)

如果您看到的确切文本通常不是代码问题 - 则表示您需要使用安装java的目录更新PATH环境变量。

答案 1 :(得分:0)

替换

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

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

这应该有所帮助。