Study:Selenium 을 바탕 으로 fireforx 자동화 테스트 를 하 는 예 입 니 다.

Maven 설정:
<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.hisky</groupId>
  <artifactId>seleniumTest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>seleniumTest</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
    	<groupId>org.seleniumhq.selenium</groupId>
    	<artifactId>selenium-java</artifactId>
    	<version>2.35.0</version>
    </dependency>
  </dependencies>
</project>
 코드 사례:
package com.hisky.seleniumTest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
 * 
 * @author zhenglin.yang
 * 
 */
public class WebTest {
	public static void main(String[] args) {
		// testSearch();
		testLogin();
	}

	private static void testSearch() {
		// System.setProperty ( "webdriver.firefox.driver" ,
		// "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" );
		WebDriver driver = new FirefoxDriver();

		driver.get("http://www.baidu.com");
		WebElement element = driver.findElement(By.name("wd"));
		element.sendKeys("  ");
		element.submit();

		(new WebDriverWait(driver, 20)).until(new ExpectedCondition<Boolean>() {
			public Boolean apply(WebDriver d) {
				return d.getTitle().toLowerCase().startsWith("  ");
			}
		});

		System.out.println("Page title is: " + driver.getTitle());

		// Close the browser
		driver.quit();
	}

	private static void testLogin() {
		// System.setProperty ( "webdriver.firefox.driver" ,
		// "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" );
		WebDriver driver = new FirefoxDriver();
		System.out.println("starts browser...");

		driver.get("http://yun.baidu.com");
		System.out.println("access login page...");

		WebElement element = driver.findElement(By.name("userName"));
		element.sendKeys("your user name...");
		System.out.println("input user name...");

		element = driver.findElement(By.name("password"));
		element.sendKeys("your password...");
		System.out.println("input password");
		element.submit();

		System.out.println("Page title is: " + driver.getTitle());

		// Close the browser
		driver.quit();
	}
}

 이상 의 내용 은 selenium 홈 페이지 튜 토리 얼 을 참고 합 니 다.fireforx 버 전 은 20 이상 이면 안 됩 니 다.그렇지 않 으 면 시작 할 수 없습니다.

좋은 웹페이지 즐겨찾기