앱피움
-
Appium 자동화 상하좌우 스크롤 하기2016.03.23
appium 에서 특정영역을 좌우로 swipe 하기
구현해보려고 한 swipe 영역
위 움짤 처럼 폴더 별 우측 슬라이드 메뉴를 제어해보려고 함
우선 우측 슬라이드 메뉴 버튼의 요소를 파악해봄
위치를 파악할 수 있는 정보가 index정보 밖에 없는 걸로 판단
index로 특정 위치를 지정해보기로 함
그래서 xpath로 버튼 위치를 가져와봄
String xpath = "//android.widget.RelativeLayout[contains(@resource-id,'item') and @index='0']"
+ "//android.widget.ImageView[contains(@resource-id,'open_edit_menu')]";
부가설명
RelativeLayout의 0번째 idex내
//android.widget.RelativeLayout[contains(@resource-id,'item') and @index='0']
open_edit_menu id를 가진 ImageView 버튼을 가져옴
//android.widget.ImageView[contains(@resource-id,'open_edit_menu')]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // 특정위치에 있는 요소의 xpath 값 String xpath = "//android.widget.RelativeLayout[contains(@resource-id,'item') and @index='0']" + "//android.widget.ImageView[contains(@resource-id,'open_edit_menu')]"; //해당 위치의 슬라이드 메뉴 왼쪽으로 swipe driver.swipeSlide(xpath); /** * 슬라이드 메뉴 swipe 하기 * @param xpath : 특정 슬라이드 메뉴의 위치 xpath * @throws Exception - Exception */ public void swipeSlide (String xpath) throws Exception { WebElement webElement = driver.findElement(By.xpath(xpath)); int starty = (int) (webElement.getLocation().getY()); int startx = (int) (webElement.getLocation().getX()); webElement.click(); driver.swipe(startx+(int)(width*0.1), starty, startx-(int)(width*0.15), starty, 0); } | cs |
이제 xpath 값을 swipeSlide 메소드에 넣어 버튼으르 클릭한 뒤
버튼의 위치를 추출해낸다.
y와 x좌표를 얻어온뒤 swipe 메소드에 값을 넣어줌
swipe 메소드는 다음과 같이 되어있다
void io.appium.java_client.AppiumDriver.swipe(int startx, int starty, int endx, int endy, int duration)
우측 startx+(int)(width*0.1) 지점에서 좌측 startx-(int)(width*0.15) 까지 swipe
(*width는 동작 초기에 폰 가로사이즈를 가져온 값)
반대 방향으로 swipe하고자 한다면 이 두값을 바꿔주면 된다.
동작시켜보면
swipe가 된다.
만약 xpath에서
//android.widget.RelativeLayout[contains(@resource-id,'item') and @index='2']
로 바꿔주면 3번째 슬라이드 메뉴가 오픈된다.
index 2 일 때 동작
3번째 폴더가 열리게 된다.
'지식메모 > 자동화' 카테고리의 다른 글
REST-Assured 를 사용하여 maven 프로젝트로 간단한 API 테스트 (0) | 2016.07.20 |
---|---|
테스터로서 느낀 4가지 실수들 (0) | 2016.06.14 |
Appium 자동화 상하좌우 스크롤 하기 (0) | 2016.03.23 |
Robotium API 기능 알아보기 (0) | 2016.02.18 |
로보티움 튜토리얼 실행해보기 (0) | 2015.09.04 |
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 |