반응형




구현해보려고 한 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 메소드에 넣어 버튼으르 클릭한 뒤

버튼의 위치를 추출해낸다.


        int starty = (int) (webElement.getLocation().getY());
        int startx = (int) (webElement.getLocation().getX());


 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번째 폴더가 열리게 된다.




반응형

+ Recent posts