본문 바로가기
QA/Test Automation

Selenium & Maven

by 화뉘 2016. 2. 3.

JAVA 설치 : http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Eclipse 설치 : http://www.eclipse.org/downloads/download.php?file=/oomph/epp/mars/R1a/eclipse-inst-win64.exe

Maven 다운로드 : http://maven.apache.org/download.cgi?Preferred=http%3A%2F%2Fapache.mirror.cdnetworks.com%2F#


Create a Project on Eclipse

File > New > Others > Maven > Maven Project

Check "create a simple project(skip archetype selection)" on New Maven Project

Input Group Id & Artifact Id on New Maven Project

add a project node on pom.xml

 

<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>SeleniumCookbook</groupId>
  <artifactId>SeleniumCookbook</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>2.25.0</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.1</version>
      <scope>test</scope>
    </dependency>  
  </dependencies>
</project>

project name > src/test/java > New > Class > input Name > Finish

Input a test code

package seleniumcookbook.example.test;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
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;
public class GoogleSearchTest {
 protected WebDriver driver;
 private StringBuffer verificationErrors = new StringBuffer();
 
 @Before
 public void setUp() {
  driver = new FirefoxDriver();
  driver.get("http://www.google.com");
 }
 @Test
 public void testGoogleSearch() {
  try {
   // name 속성으로 텍스트 입력 엘리먼트만 찾는다.
   WebElement element = driver.findElement(By.name("q"));
   // 검색어응 입력한다.
   element.sendKeys("Selenium testing tools cookbook");
   // 웹드라이버는 폼 엘리먼트를 찾아 제출한다.
   element.submit();
   (new WebDriverWait(driver, 10)).until
       (new ExpectedCondition<Boolean>() {
    public Boolean apply(WebDriver d) {
     return d.getTitle().toLowerCase().startsWith("selenium testing tools cookbook");
    }
   });
   
   assertEquals("Selenium testing tools cookbook - Google Search", driver.getTitle());
  } catch (Error e) {
   verificationErrors.append(e.toString());
  }
 }
 
 @After
 public void tearDown() throws Exception {
  driver.quit();
  String verificationErrorString = verificationErrors.toString();
  if (!"".equals(verificationErrorString)) {
   fail(verificationErrorString);
  }
  
 }

Runs As > Maven test


Trouble Shooting

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile

Windows -> Preferences -> Java -> Installed JREs -> jdk

JRE 경로가 JAVA 디렉토리에 있는 것이 아닌 JAVA 밑에 JDK 안에 있는 것으로 선택하면 된다.
 

'QA > Test Automation' 카테고리의 다른 글

PyWinAuto For UI Automation  (0) 2016.02.17
AutoIT For UI Automation  (0) 2016.02.17
Sikuli For UI Automation  (0) 2016.02.17
UFT(Unified Functional Testing) Mobile  (0) 2016.02.03
Sikuli For UI Automation  (0) 2014.11.27

댓글