테스트
-
Rest-assured를 사용하여 간단한 Naver Open API 테스트2017.03.13
-
REST-Assured 를 사용하여 maven 프로젝트로 간단한 API 테스트2016.07.20
-
Appium 자동화 상하좌우 스크롤 하기2016.03.23
-
PlayFramework 2 테스트 방법2013.07.17
Rest-assured를 사용하여 간단한 Naver Open API 테스트
Naver Open API가 방식이 바뀌어서 이전 글에서 했던 방식은 동작이 되지않는다.
하지만 사전 준비는 동일하니 아래 글을 참고하면 된다.
REST-Assured 를 사용하여 maven 프로젝트로 간단한 API 테스트
http://yonoo88.tistory.com/886
우선 네이버오픈API 페이지에 들어간다.
https://developers.naver.com/main/
들어가서 상단 Application > 애플리케이션 등록을 들어간다.
애플리케이션 이름적고 사용할 API 추가하고 환경은 저렇게 해주어도 된다.
등록하기를 누르면 아래와 같은 화면이 나오는데
Client ID 와 Client Secret 저 2개가 필요하다.
Client Secret는 우측 보기를 누르면 표시된다.
이 2개를 복사해서 코드에 넣어주어야 한다.
저 2개 값을 header 값으로 추가해주어야 한다.
String 값으로 Client ID,와 Client Secret 에 개인 값을 넣어준다.
그럼 api가 정상적으로 동작한다.
예제코드 뉴스 검색 API 사용
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | package NaverAPITest.NAPITest; import static io.restassured.RestAssured.*; import static org.hamcrest.Matchers.*; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import org.junit.Before; import org.junit.Test; public class test { @Before public void apiTest() { baseURI = "http://openapi.naver.com"; // baseURI = "http://maps.googleapis.com"; port = 80; } @Test public void test() { try { String text = URLEncoder.encode("최순실", "UTF-8"); given(). header("X-Naver-Client-Id", "Client ID"). header("X-Naver-Client-Secret","Client Secret"). params( //URL 주소의 파라미터 값을 넣어줌 "query",text ).when(). /*baseURL 을 제외한 뒷부분 주소를 get하고 *body에서 해당 title 내용을 가져올 위치 지정 후 *확인할 값을 equalTo에 넣어 확인*/ get("/v1/search/news.xml").then().body("rss.channel.title", equalTo("Naver Open API - news ::'최순실'")); // get("/v1/search/news.xml").then().toString(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } | cs |
'지식메모 > 자동화' 카테고리의 다른 글
selenium 크롬 자동화 할 때 현재 실행중인 크롬에서 실행하기 (3) | 2019.01.04 |
---|---|
python과 java 에서 selenium 으로 크롬 자동화시 chromedriver.exe 프로세스 죽이기 (1) | 2018.12.30 |
Selenium 을 이용한 버거킹 영수증 설문조사 자동화 (0) | 2016.07.25 |
REST-Assured 를 사용하여 maven 프로젝트로 간단한 API 테스트 (0) | 2016.07.20 |
테스터로서 느낀 4가지 실수들 (0) | 2016.06.14 |
REST-Assured 를 사용하여 maven 프로젝트로 간단한 API 테스트
eclipse 에서 maven 프로젝트를 새로 생성한다.
create a simple.. 체크해주었다
이름을 짓고 피니쉬
src/test/java 에 새 패키지를 추가했다.
이런 식으로..
거기에 Junit Test Case 를 생성한다.
그리고 maven 프로젝트의 pom.xml에 다음과 같은 내용을 추가해준다.
https://github.com/rest-assured/rest-assured/wiki/GettingStarted
위 링크로 가면 자세히 나와있다.
우선 그냥
REST Assured
JsonPath
XmlPath
JSON Schema Validation
4가지를 추가해줬다.
4가지 추가된 모습
예제로 네이버 open api 에서 해보았다.
http://developer.naver.com/wiki/pages/SrchBook
위 링크에 들어가면 예시 URL과 함께 파라미터 값도 나와있다
1. 요청 URL (request url)#
http://openapi.naver.com/search
2. 요청 변수 (request parameter)#
2.1 기본검색#
요청 변수 | 값 | 설명 |
---|---|---|
key | string (필수) | 이용 등록을 통해 받은 key 스트링을 입력합니다. |
target | string (필수) : book | 서비스를 위해서는 무조건 지정해야 합니다. |
query | string (필수) | 검색을 원하는 질의, UTF-8 인코딩 입니다. |
display | integer : 기본값 10, 최대 100 | 검색결과 출력건수를 지정합니다. 최대 100 까지 가능합니다. |
start | integer : 기본값 1, 최대 1000 | 검색의 시작위치를 지정할 수 있습니다. 최대 1000 까지 가능합니다. |
- 샘플 URL ('삼국지'를 검색할 경우)
http://openapi.naver.com/search?key=c1b406b32dbbbbeee5f2a36ddc14067f&query=%EC%82%BC%EA%B5%AD%EC%A7%80&display=10&start=1&target=book
위 링크의 예제 URL로 들어가보면
아래와 같은 페이지가 노출되는데
여기 xml값 중 title 내용으로 확인을 해보았다.
아래와 같이 끄적끄적 한 뒤
given().when() 이런 것들은 아직 잘 모름
예시대로 해본 것 뿐
예시코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | package rest.test.api.com; import static org.junit.Assert.fail; import org.junit.Before; import static io.restassured.RestAssured.*; import static io.restassured.matcher.RestAssuredMatchers.*; import static org.hamcrest.Matchers.*; import static io.restassured.module.jsv.JsonSchemaValidator.*; import org.junit.Test; public class APITest { public APITest() { baseURI = "http://openapi.naver.com"; port = 80; } @Test public void test() { given(). params( //URL 주소의 파라미터 값을 넣어줌 "key","c1b406b32dbbbbeee5f2a36ddc14067f", "query","삼국지", "display","10", "start","1", "target", "book" ).when(). /*baseURL 을 제외한 뒷부분 주소를 get하고 *body에서 해당 title 내용을 가져올 위치 지정 후 *확인할 값을 equalTo에 넣어 확인*/ get("/search").then().body("rss.channel.title", equalTo("Naver Open API - book ::'sample'")); } } | cs |
값이 일치한다면 아래처럼 정상적으로 테스트가 초록색으로 끝난다.
'지식메모 > 자동화' 카테고리의 다른 글
Rest-assured를 사용하여 간단한 Naver Open API 테스트 (0) | 2017.03.13 |
---|---|
Selenium 을 이용한 버거킹 영수증 설문조사 자동화 (0) | 2016.07.25 |
테스터로서 느낀 4가지 실수들 (0) | 2016.06.14 |
appium 에서 특정영역을 좌우로 swipe 하기 (2) | 2016.05.23 |
Appium 자동화 상하좌우 스크롤 하기 (0) | 2016.03.23 |
Appium 자동화 상하좌우 스크롤 하기
swipe를 이용한 상하좌우 스크롤 및 스크롤 새로고침 구현
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | import io.appium.java_client.AppiumDriver; import io.appium.java_client.TouchAction; import io.appium.java_client.android.AndroidDriver; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import java.util.NoSuchElementException; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; //import org.junit.Test; import org.testng.annotations.Test; public class Utilities extends AndroidDriver<WebElement> implements TakesScreenshot { Dimension size = manage().window().getSize(); /** * 위로 스크롤 */ public void scrollUp() throws Exception { Thread.sleep(2000); int starty = (int) (size.height * 0.80); int endy = (int) (size.height * 0.20); int startx = size.width / 2; System.out.println("startx = " + startx + " ,endy = " + endy + " , starty = " + starty); //올리기 this.swipe(startx, endy, startx, starty, 0); Thread.sleep(2000); } /** * 아래로 스크롤 */ public void scrollDown() throws Exception { Thread.sleep(2000); int starty = (int) (size.height * 0.80); int endy = (int) (size.height * 0.20); int startx = size.width / 2; // System.out.println("startx = " + startx + " ,endy = " + endy + " , starty = " + starty); //내려가기 swipe(startx, starty, startx, endy, 0); Thread.sleep(2000); } /** * 스크롤 새로고침 */ public void pullToRefresh() throws Exception { Thread.sleep(1000); int starty = (int) (size.height * 0.5); int endy = (int) (size.height * 0.9); int startx = (int) (size.width*0.01); // System.out.println("startx = " + startx + " ,endy = " + endy + " , starty = " + starty); //내려가기 swipe(startx, starty, startx, endy, 0); Thread.sleep(2000); } /** * 오른쪽에서 왼쪽으로 Swipe */ public void swipeToLeft() throws Exception { Thread.sleep(2000); int starty = (int) (size.width * 0.80); int endx = (int) (size.width * 0.20); int startx = size.height / 2; swipe(startx, starty, endx, starty, 0); Thread.sleep(2000); } /** * 왼쪽에서 오른쪽으로 Swipe */ public void swipeToRight() throws Exception { Thread.sleep(2000); int starty = (int) (size.width * 0.80); int endx = (int) (size.width * 0.20); int startx = size.height / 2; swipe(endx, starty, startx, starty, 0); Thread.sleep(2000); } } | cs |
'지식메모 > 자동화' 카테고리의 다른 글
테스터로서 느낀 4가지 실수들 (0) | 2016.06.14 |
---|---|
appium 에서 특정영역을 좌우로 swipe 하기 (2) | 2016.05.23 |
Robotium API 기능 알아보기 (0) | 2016.02.18 |
로보티움 튜토리얼 실행해보기 (0) | 2015.09.04 |
Selenium & Webdriver 자동화 테스트 예제 - Naver 지식인 (크롬 브라우저) (0) | 2015.01.23 |
PlayFramework 2 테스트 방법
해당 프로젝트로 가서
play
해서 플레이 콘솔창으로 들어간 다음
test
하면 모든 테스트 진행
test-only 폴더명.패키지명.클래스명
상황에 따라
test-only 패키지명.클래스명
test-only 클래스명
하면 특정 클래스만 테스트 진행
플레이프레임워크 사이트에서 설명
'지식메모 > PlayFramework 2' 카테고리의 다른 글
자바에서 쉘스크립트 실행하기 (0) | 2013.07.22 |
---|