반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

Selenium WebDriver Tutorial 01

2013. 10. 17. 17:25 | Posted by 솔웅


반응형

Selenium WebDriver

NOTE: We’re currently working on documenting these sections. We believe the information here is accurate, however be aware we are also still working on this chapter. Additional information will be provided as we go which should make this chapter more solid.



Introducing WebDriver



Selenium 2.0 의 새 기능중 중요한 부분은 WebDriver API 를 통합했다는 겁니다. WebDriver는 Selenium-RC API 의 한계를 극복하기 위한 기능들이 추가 된 것으로 프로그래밍을 좀 더 간단하고 간결하게 할 수 있도록 도와 줍니다. Selenium-WebDriver는 페이지가 reload 되지 않고도 페이지의 element들이 바뀌는 dynamic web page를 좀 더 제대로 지원하기 위해 만들었습니다. WebDriver의 목표는 현재 Web-App의 문제점들을 제대로 해결하기 위해 만들어진 잘 디자인된 객체 지향 API 입니다.



How Does WebDriver ‘Drive’ the Browser Compared to Selenium-RC?



Selenium-WebDriver는 자동화를 위해 각 브라우저 고유의 기능들을 지원함으로서 브라우저에 직접 호출하는 기능을 지원합니다. 어떻게 이렇게 직접 호출을 할 수 있고 어떤 기능들을 지원하느냐는 여러분이 사용하는 브라우저에 따라 다릅니다. 각 browser driver에 대한 정보는 나중에 살펴 보겠습니다.



Selenium-RC에 익숙하신 분들에게는 이 부분이 여러분이 사용하시던 부분과 좀 다를 겁니다. Selenium-RC는 각 브라우저에 대해 같은 방법으로 작독했습니다. 브라우저가 로드 되면 그 브라우저에 자바스크립트를 inject 하고 그 브라우저 안에서 AUT를 drive 하기 위해 그 자바스크립트를 사용합니다. WebDriver는 이와 같이 작동하지 않습니다. WebDriver는 automation을 위해 지원하는 브라우저의 고유 기능을 direct 하게 사용합니다.


WebDriver and the Selenium-Server



이 Selenium-WebDriver를 어떻게 사용할 것인가에 따라 Selenium Server가 필요할 수도 있고 그렇지 않을 수도 있습니다. 만약 WebDriver API 만을 사용할 거라면 Selenium-Server는 필요하지 않습니다. 만약 여러분의 브라우저와 테스트들이 같은 machine 에서 작동하고 여러분의 테스트가 WebDriver API만을 사용한다면 Selenium-Server가 필요하지 않습니다. WebDriver가 곧바로 그 브라우저를 실행시킬 겁니다.



Selenium-WebDriver와 함께 Selenium-Server를 사용하는데는 몇가지 이유가 있습니다.

       

- 여러분의 tests를 여러 machine들이나 virtual machines(VMs)에서 사용하기 위해 Selenium-Grid를 사용하는 경우.
      

- 여러분의 machine에 있지 않는 브라우저 버전을 갖고 있는 다른 machine에 remote로 접근해야 할 경우.
       

- Java bindings (Python,C#,Ruby 같은) 을 사용하지 않고 HtmlUnit Driver를 사용 할 경우.



Setting Up a Selenium-WebDriver Project



Selenium 을 인스톨한다는 의미는 development에 project를 셋업한다는 얘기입니다. 그렇게 되면 Selenium을 사용해서 프로그래밍 할 수 있게 되는거죠. 이것을 프로그래밍 언오와 개발환경에 따라 어떻게 할까요.





JAVA



Selenium 2.0 Java 프로젝트를 셋업하는 가장 쉬운 방법은 Maven을 이용하는 겁니다. Maven 은 java binding들 (Selenium 2.0 java client library)와 모든 dependency들을 다운로드 하고 프로젝트를 생성할 겁니다. 메이븐의 pom.xml (project configuration) 파일을 사용해서 이러한 일을 하시면 됩니다. 이 작업이 완료 되면 여러분은 maven 프로젝트를 여러분이 사용하시는 IDE (IntelliJ IDEA 나 이클립스)에 import 하실 수 있습니다.



첫번째로 Selenium project 파일들이 들어갈 폴더를 생성합니다. Maven을 사용하려면 pom.xml 파일이 필요합니다. 이 파일은 텍스트 에디터로 만들 수 있습니다. 이 pom.xml 파일이나 메이븐에 대한 자세한 부분은 다루지 않겠습니다. 아마 pom.xml은 아래와 같을 겁니다. 여러분 프로젝트를 위해 만든 폴더에 이 파일을 생성해 넣으세요.



<?xml version="1.0" encoding="UTF-8"?>
<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>MySel20Proj</groupId>
        <artifactId>MySel20Proj</artifactId>
        <version>1.0</version>
        <dependencies>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>2.35.0</version>
            </dependency>
            <dependency>
                <groupId>com.opera</groupId>
                <artifactId>operadriver</artifactId>
            </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>



이 때 최신 버전을 사용하세요. 위 코드 내의 버전들은이 글을 쓸 당시의 최종 버전들입니다. Maven download page를 체크하셔서 위의 코드 중 버전이 바뀐 경우 바꿔주세요.



이제 command-line에서 cd 로 해당 프로젝트 디렉토리로 가셔서 아래처럼 maven을 run 해 주세요.



mvn clean install



이렇게 하면 Selenium과 다른 dependency들을 다운받아 프로젝트에 추가할 겁니다.



마지막으로 이 프로젝트를 개발환경에 import 하시면 됩니다. 이 방법을 자세히 아시려면 아래 링크를 따라 가서 참고하시면 도움이 될 겁니다.



Importing a maven project into IntelliJ IDEA. Importing a maven project into Eclipse.



C#



As of Selenium 2.2.0, the C# bindings are distributed as a set of signed dlls along with other dependency dlls. Prior to 2.2.0, all Selenium dll’s were unsigned. To include Selenium in your project, simply download the latest selenium-dotnet zip file from https://code.google.com/p/selenium/downloads/list. If you are using Windows Vista or above, you should unblock the zip file before unzipping it: Right click on the zip file, click “Properties”, click “Unblock” and click “OK”.



Unzip the contents of the zip file, and add a reference to each of the unzipped dlls to your project in Visual Studio (or your IDE of choice).



Official NuGet Packages: RC WebDriver WebDriverBackedSelenium Support


Python



If you are using Python for test automation then you probably are already familiar with developing in Python. To add Selenium to your Python environment run the following command from a command-line.



pip install selenium



Pip requires pip to be installed, pip also has a dependency on setuptools.



Teaching Python development itself is beyond the scope of this document, however there are many resources on Python and likely developers in your organization can help you get up to speed.
Ruby



If you are using Ruby for test automation then you probably are already familiar with developing in Ruby. To add Selenium to your Ruby environment run the following command from a command-line.



gem install selenium-webdriver



Teaching Ruby development itself is beyond the scope of this document, however there are many resources on Ruby and likely developers in your organization can help you get up to speed.



Perl



Perl bindings are provided by a third party, please refer to any of their documentation on how to install / get started. There is one known Perl binding as of this writing.



PHP



PHP bindings are provided by a third party, please refer to any of their documentation on how to install / get started. There are three known bindings at this time: By Chibimagic By Lukasz Kolczynski and By the Facebook

반응형