From 90564026d9a743bcf5990bf764e54d9b0323710b Mon Sep 17 00:00:00 2001 From: chongzi <chongzi@symbio.com> Date: Mon, 23 Nov 2015 18:23:04 +0800 Subject: [PATCH 1/2] may commit --- pom.xml | 43 ++++++ .../baidu/test/SearchWhichWayToSelect.java | 129 ++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/com/baidu/test/SearchWhichWayToSelect.java diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..6ba1e46 --- /dev/null +++ b/pom.xml @@ -0,0 +1,43 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>com.baidu.test</groupId> + <artifactId>MapPractise</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>MapPractise</name> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-java</artifactId> + <version>2.48.2</version> + </dependency> + + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>6.8</version> + <scope>test</scope> + </dependency> + </dependencies> + <dependencyManagement> + <dependencies> + <dependency> + <groupId>com.opera</groupId> + <artifactId>operadriver</artifactId> + <version>1.5</version> + <exclusions> + <exclusion> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-remote-driver</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + </dependencyManagement> + + + +</project> \ No newline at end of file diff --git a/src/main/java/com/baidu/test/SearchWhichWayToSelect.java b/src/main/java/com/baidu/test/SearchWhichWayToSelect.java new file mode 100644 index 0000000..883a0d5 --- /dev/null +++ b/src/main/java/com/baidu/test/SearchWhichWayToSelect.java @@ -0,0 +1,129 @@ +package com.baidu.test; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +public class SearchWhichWayToSelect { + + private WebDriver dr = new FirefoxDriver(); +// private WebDriverWait wait = new WebDriverWait(dr,80000); + + @FindBy(css = ".ui3-city-change-inner.ui3-control-shadow") + private WebElement city; + + @FindBy(css = "a[name='�Ϻ�']") + private WebElement shangHaiCityItem; + + @FindBy(css = "a[name='����']") + private WebElement beiJingCityItem; + + @FindBy(css = ".subway-item") + private WebElement subWay; + + @FindBy(id = "route_menu") + private WebElement routeMenu; + + @FindBy(css = ".route_menu") + private WebElement bus; + + @FindBy(id = "bus_start_input") + private WebElement bus_start; + + @FindBy(id = "bus_end_input") + private WebElement bus_end; + + @FindBy(id = "sub_start_input") + private WebElement startFrom; + + @FindBy(id = "sub_end_input") + private WebElement endFrom; + + @FindBy(id = "busSearchBtn") + private WebElement busSearchButton; + + @FindBy(id = "subSearchBtn") + private WebElement searchButton; + + @FindBy(id = "btn_uf") + private WebElement detailButton; + + @FindBy(css = "#routes_detail") + private WebElement detail; + + @FindBy(css = "#select_type") + private WebElement trafficType;// ���ﲻ����css = .traffic_type ��λ,�����ʱ������¼��������� + + @FindBy(css = ".nosubway") + private WebElement noSubWay; + + @FindBy(css = "#scheme_0 .bus_time") + private WebElement FirstItemBusTime; + + public SearchWhichWayToSelect() { + PageFactory.initElements(dr, this); + } + @Test + public void test() throws InterruptedException { + dr.get("http://map.baidu.com/"); + Thread.sleep(20000); + this.city.click(); + Thread.sleep(3000); + this.shangHaiCityItem.click(); + Thread.sleep(3000); + this.subWay.click(); + Thread.sleep(3000); + this.startFrom.sendKeys("�Ϻ���ѧ"); + Thread.sleep(3000); + this.endFrom.sendKeys("½����"); + Thread.sleep(3000); + this.searchButton.click(); + Thread.sleep(3000); + this.detailButton.click(); + Thread.sleep(8000); + System.out.println(this.detail.getText()); + Thread.sleep(9000); + + + } + + @Test + public void test2() throws InterruptedException { + dr.get("http://map.baidu.com/"); + Thread.sleep(20000); + this.city.click(); + Thread.sleep(3000); + this.beiJingCityItem.click(); + Thread.sleep(10000); + this.routeMenu.click(); + Thread.sleep(3000); + this.bus_start.sendKeys("�ϵ����"); + Thread.sleep(3000); + this.bus_end.sendKeys("�ʹ�"); + Thread.sleep(3000); + this.busSearchButton.click(); + Thread.sleep(30000); + this.trafficType.click(); + + Thread.sleep(8000); + this.noSubWay.click(); + Thread.sleep(9000); + System.out.println(this.FirstItemBusTime.getText()); + + } + @AfterClass + public void afterClass(){ + dr.close(); + } + + // @Test + // public void test3() throws InterruptedException{ + // this.test2(); + // } + +} From b8b644e9b139aeb753b8589c1601032d9058e21a Mon Sep 17 00:00:00 2001 From: chongzi <chongzi@symbio.com> Date: Mon, 23 Nov 2015 18:42:16 +0800 Subject: [PATCH 2/2] second commit --- .../com/baidu/test/SearchWhichWayToSelect.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/baidu/test/SearchWhichWayToSelect.java b/src/main/java/com/baidu/test/SearchWhichWayToSelect.java index 883a0d5..f774279 100644 --- a/src/main/java/com/baidu/test/SearchWhichWayToSelect.java +++ b/src/main/java/com/baidu/test/SearchWhichWayToSelect.java @@ -17,10 +17,10 @@ public class SearchWhichWayToSelect { @FindBy(css = ".ui3-city-change-inner.ui3-control-shadow") private WebElement city; - @FindBy(css = "a[name='�Ϻ�']") + @FindBy(css = "a[name='上海']") private WebElement shangHaiCityItem; - @FindBy(css = "a[name='����']") + @FindBy(css = "a[name='北京']") private WebElement beiJingCityItem; @FindBy(css = ".subway-item") @@ -57,7 +57,7 @@ public class SearchWhichWayToSelect { private WebElement detail; @FindBy(css = "#select_type") - private WebElement trafficType;// ���ﲻ����css = .traffic_type ��λ,�����ʱ������¼��������� + private WebElement trafficType;// 这里不能用css = .traffic_type 定位,用这个时,点击事件不起作用 @FindBy(css = ".nosubway") private WebElement noSubWay; @@ -78,9 +78,9 @@ public void test() throws InterruptedException { Thread.sleep(3000); this.subWay.click(); Thread.sleep(3000); - this.startFrom.sendKeys("�Ϻ���ѧ"); + this.startFrom.sendKeys("上海大学"); Thread.sleep(3000); - this.endFrom.sendKeys("½����"); + this.endFrom.sendKeys("陆家嘴"); Thread.sleep(3000); this.searchButton.click(); Thread.sleep(3000); @@ -102,9 +102,9 @@ public void test2() throws InterruptedException { Thread.sleep(10000); this.routeMenu.click(); Thread.sleep(3000); - this.bus_start.sendKeys("�ϵ����"); + this.bus_start.sendKeys("上地五街"); Thread.sleep(3000); - this.bus_end.sendKeys("�ʹ�"); + this.bus_end.sendKeys("故宫"); Thread.sleep(3000); this.busSearchButton.click(); Thread.sleep(30000);