如何使用webdriver.io?

时间:2017-03-07 19:38:27

标签: selenium-webdriver appium webdriver-io

我正在尝试使用webdriver.io框架滚动iOS本机应用程序。 我正在使用此API: browser.touchAction({   动作:'moveTo',x:1,y:2 });

收到错误:尚未实施。还有其他滚动方法吗?

6 个答案:

答案 0 :(得分:1)

browser.execute('mobile:scroll',{direction:down});

参考: https://appium.readthedocs.io/en/latest/en/commands/mobile-command

还有一个解决方法命令,可滚动到指定的选择器。

browser.getLocation(选择器);

选择器可以是xpath / css选择器

答案 1 :(得分:0)

我认为你使用的是错误的api点。根据webdriver.io网站上的api文档,您应该使用 browser.touchScroll(ID,X偏移,Y偏移);

你可以在这里查看http://webdriver.io/api/protocol/touchScroll.html#description

答案 2 :(得分:0)

答案:

browser.touchAction([{action:'press',x:10,y:firstY},{action:'moveTo',x:10,y:secondY},'release'])

答案 3 :(得分:0)

想让你知道,在appium版本1.3 +

中不推荐使用内置滚动方法
Now you can use swipe method
browser.swipe([selector][,xoffset][,yoffset][,speed]);

选择器是元素

xoffset - relative x cordinate

yoffset-相对y坐标

速度 - 应以ms为单位执行操作

答案 4 :(得分:0)

使用此命令滚动:

client.execute("mobile: scroll", {direction: 'down'})

答案 5 :(得分:0)

PlayState = Class{__includes = BaseState}

function PlayState:init()
    -- start our transition alpha at full, so we fade in
    self.transitionAlpha = 255

    -- position in the grid which we're highlighting
    self.boardHighlightX = 0
    self.boardHighlightY = 0

    -- timer used to switch the highlight rect's color
    self.rectHighlighted = false

    -- flag to show whether we're able to process input (not swapping or clearing)
    self.canInput = true

    -- tile we're currently highlighting (preparing to swap)
    self.highlightedTile = nil

    self.score = 0
    self.timer = 60

    -- set our Timer class to turn cursor highlight on and off
    Timer.every(0.5, function()
        self.rectHighlighted = not self.rectHighlighted
    end)

    -- subtract 1 from timer every second
    Timer.every(1, function()
        self.timer = self.timer - 1

        -- play warning sound on timer if we get low
        if self.timer <= 5 then
            gSounds['clock']:play()
        end
    end)
end

function PlayState:enter(params)
    -- grab level # from the params we're passed
    self.level = params.level

    -- spawn a board and place it toward the right
    self.board = params.board or Board(VIRTUAL_WIDTH - 272, 16)

    -- grab score from params if it was passed
    self.score = params.score or 0

    -- score we have to reach to get to the next level
    self.scoreGoal = self.level * 1.25 * 1000
end

function PlayState:update(dt)
    if love.keyboard.wasPressed('escape') then
        love.event.quit()
    end

    -- go back to start if time runs out
    if self.timer <= 0 then
        -- clear timers from prior PlayStates
        Timer.clear()
        
        gSounds['game-over']:play()

        gStateMachine:change('game-over', {
            score = self.score
        })
    end

    -- go to next level if we surpass score goal
    if self.score >= self.scoreGoal then
        -- clear timers from prior PlayStates
        -- always clear before you change state, else next state's timers
        -- will also clear!
        Timer.clear()

        gSounds['next-level']:play()

        -- change to begin game state with new level (incremented)
        gStateMachine:change('begin-game', {
            level = self.level + 1,
            score = self.score
        })
    end

    if self.canInput then
        -- move cursor around based on bounds of grid, playing sounds
        if love.keyboard.wasPressed('up') then
            self.boardHighlightY = math.max(0, self.boardHighlightY - 1)
            gSounds['select']:play()
        elseif love.keyboard.wasPressed('down') then
            self.boardHighlightY = math.min(7, self.boardHighlightY + 1)
            gSounds['select']:play()
        elseif love.keyboard.wasPressed('left') then
            self.boardHighlightX = math.max(0, self.boardHighlightX - 1)
            gSounds['select']:play()
        elseif love.keyboard.wasPressed('right') then
            self.boardHighlightX = math.min(7, self.boardHighlightX + 1)
            gSounds['select']:play()
        end

        -- if we've pressed enter, to select or deselect a tile...
        if love.keyboard.wasPressed('enter') or love.keyboard.wasPressed('return') then
            -- if same tile as currently highlighted, deselect
            local x = self.boardHighlightX + 1
            local y = self.boardHighlightY + 1
            
            -- if nothing is highlighted, highlight current tile
            if not self.highlightedTile then
                self.highlightedTile = self.board.tiles[y][x]

            -- if we select the position already highlighted, remove highlight
            elseif self.highlightedTile == self.board.tiles[y][x] then
                self.highlightedTile = nil

            -- if the difference between X and Y combined of this highlighted tile
            -- vs the previous is not equal to 1, also remove highlight
            elseif math.abs(self.highlightedTile.gridX - x) + math.abs(self.highlightedTile.gridY - y) > 1 then
                gSounds['error']:play()
                self.highlightedTile = nil
            else
                self:swapTiles(self.highlightedTile, self.board.tiles[y][x], true)
            end
        end
    end

    Timer.update(dt)
end


function PlayState:swapTiles(tile1, tile2, swapBackAtNoMatch)

    local tile1 = tile1
    local tile2 = tile2
    local swapBackAtNoMatch = swapBackAtNoMatch

    self.board:swapTiles(tile1, tile2) -- Causes the nil error.

    if swapBackAtNoMatch then
    -- tween coordinates between two swapping tiles
    Timer.tween(0.1, {
        [tile1] = {x = tile2.x, y = tile2.y},
        [tile2] = {x = tile1.x, y = tile1.y}
    })

    -- once they've swapped, tween falling blocks
    :finish(function ()

        local matches = self.board:calculateMatches()
        if matches then
            self.calculateMatches(matches)
        else

            -- swap back if there's no match
            self.swapTiles(tile1, tile2, false)

            gSounds['error']:play()
        end
    end)
    else
    -- tween coordinates between the two so they swap
    Timer.tween(0.1, {
        [tile1] = {x = tile2.x, y = tile2.y},
        [tile2] = {x = tile1.x, y = tile1.y}})
    end

end

--[[
    Calculates whether any matches were found on the board and tweens the needed
    tiles to their new destinations if so. Also removes tiles from the board that
    have matched and replaces them with new randomized tiles, deferring most of this
    to the Board class.
]]
function PlayState:calculateMatches()
    self.highlightedTile = nil

    -- if we have any matches, remove them and tween the falling blocks that result
    local matches = self.board:calculateMatches()
    
    if matches then
        gSounds['match']:stop()
        gSounds['match']:play()

        -- add score for each match
        for k, match in pairs(matches) do

            local varietyPoints = 0 -- We'll keep track of the bonus variety points here
             -- We'll use vareity to calculate points for each tile within a match
             for j, tiles in pairs(match) do
                
                    varietyPoints = varietyPoints + tiles.variety * 25


            end
            
            self.score = self.score + (#match * 50) + varietyPoints

           

            -- Also add one second times the number of match to the timer
            self.timer = self.timer + #match * 1

        end

        -- remove any tiles that matched from the board, making empty spaces
        self.board:removeMatches()

        -- gets a table with tween values for tiles that should now fall
        local tilesToFall = self.board:getFallingTiles()

        -- first, tween the falling tiles over 0.25s
        Timer.tween(0.25, tilesToFall):finish(function()
            local newTiles = self.board:getNewTiles()
            
            -- then, tween new tiles that spawn from the ceiling over 0.25s to fill in
            -- the new upper gaps that exist
            Timer.tween(0.25, newTiles):finish(function()
                -- recursively call function in case new matches have been created
                -- as a result of falling blocks once new blocks have finished falling
                self:calculateMatches()
            end)
        end)
    -- if no matches, we can continue playing
    else
        self.canInput = true
    end
end

使用y = -ve值向下滚动。