import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.openqa.selenium.WebDriver;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class BaseTestCase {
public WebDriver driver;
public static Map ReadXml(String path) throws ParserConfigurationException,
IOException, SAXException {
Map map = new LinkedHashMap();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Properties properties = System.getProperties();
String stream = properties.getProperty("user.dir") + path;
File f = new File(stream);
if (f.exists()) {
Document doc = builder.parse(f);
Element root = (Element) doc.getDocumentElement();
NodeList list = root.getElementsByTagName("dictionary");
for (int i = 0; i < list.getLength(); i++) {
String key = list.item(i).getAttributes().getNamedItem("key").getNodeValue();
String value = list.item(i).getAttributes().getNamedItem("value").getNodeValue();
map.put(key, value);
}
}
return map;
}
}
/////////////////////////////////////////////////////////////////////////
import static org.junit.Assert.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import javax.xml.parsers.ParserConfigurationException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.xml.sax.SAXException;
/**
* @author yang.zhou
*
*/
public class Demotest extends BaseTestCase {
public WebDriver driver;
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
// System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void
test() throws ParserConfigurationException, SAXException,
IOException, InterruptedException {
driver.get("
");
Map map = ReadXml("\\DataXml\\Online.xml");
driver.findElement(By.id("DepartCity1TextBox")).clear();
Thread.sleep(500);
driver.findElement(By.id("DepartCity1TextBox")).sendKeys(map.get("出发城市").toString());
Thread.sleep(1000);
}
}