class WDA
Created by Yi MIN<yi@zen.ly> Copyright © 2017 Zenly. All rights reserved.
Created by Yi MIN<yi@zen.ly> Copyright © 2017 Zenly. All rights reserved.
Created by Yi MIN<yi@zen.ly> Copyright © 2017 Zenly. All rights reserved.
Created by Yi MIN<yi@zen.ly> Copyright © 2017 Zenly. All rights reserved.
Created by Yi MIN Copyright © 2017 Zenly. All rights reserved.
Created by Yi MIN<yi@zen.ly> Copyright © 2017 Zenly. All rights reserved.
Created by Yi MIN<yi@zen.ly> Copyright © 2017 Zenly. All rights reserved.
Created by Yi MIN<yi@zen.ly> Copyright © 2017 Zenly. All rights reserved.
Created by Yi MIN<yi@zen.ly> Copyright © 2017 Zenly. All rights reserved.
Created by Yi MIN<yi@zen.ly> Copyright © 2017 Zenly. All rights reserved.
Created by Yi MIN<yi@zen.ly> Copyright © 2017 Zenly. All rights reserved.
Licensed to the Software Freedom Conservancy (SFC) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The SFC licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Constants
- BASE_URL
Get
base_url
from XCTRunner logs: ServerURLHere->x.x.x.x:8100<-ServerURLHere Defaultbase_url
'localhost:8100' for running XCTRunner on simulator- Dimension
- Point
- VERSION
Attributes
Public Class Methods
Create a new client
“`ruby require 'rubygems' require 'wda_lib'
Start wda client opts = { caps: { bundleId: @bundle_id }, device_url: 'x.x.x.x:8100' } WDA.new(opts)
.start_session
# File lib/wda_lib.rb, line 49 def initialize(opt) # fail 'opts should be a hash' unless opts.is_a? Hash # fail 'bundleId should be provided' if opts[:bundle_id].nil? if opt.is_a? String url = opt opts = {:device_url => url} else opts = opt end url = opts[:device_url] || BASE_URL parsed_url = URI.parse(url) @base_url = parsed_url.scheme + '://' + parsed_url.host + ':' + parsed_url.port.to_s @url = @base_url @server_host = parsed_url.host @server_port = parsed_url.port @default_timeout = opts.fetch :default_timeout, 10 @timeout = @default_timeout @listener = opts.fetch :listener, nil status window_size capabilities(opts) end
Public Instance Methods
Build desired_capabilities with options @param opts [Hash] @return attribute caps [Hash]
# File lib/wda_lib.rb, line 75 def capabilities(opts = {}) @bundle_id = opts[:bundle_id] if !opts[:bundle_id].nil? selenium_capabilities = Selenium::WebDriver::Remote::Capabilities.new( platform_name: @platform_name, platform_version: @platform_version, session_id: @session_id, session_valid: @session_valid, bundleId: @bundle_id, javascript_enabled: true, takes_screenshot: true, css_selectors_enabled: true ) @caps = { desired_capabilities: selenium_capabilities } end
# File lib/wda_lib.rb, line 109 def delete(path) WDA.delete(path) end
Double tap on a given positon @param x [Integer], y [Integer]
# File lib/wda_lib/element.rb, line 186 def double_tap(x, y) post '/wda/doubleTap', { x: x, y: y } end
HTTP methods for dealing with all supported motheds in FB WDA
I don't like to write such pieces of code, it removes all query params and headers, But as FB WDA
is doing like this, this can simplify codes
# File lib/wda_lib.rb, line 93 def get(path, timeout = 60) if URI.parse(path).absolute? WDA.get(path, timeout: timeout) else WDA.get(@url + path, timeout: timeout) end end
Type
text to textfield @param value [String]
# File lib/wda_lib/element.rb, line 199 def keys(value) post '/wda/keys', { value: value.chars } end
# File lib/wda_lib.rb, line 101 def post(path, body = nil, timeout = 60) if URI.parse(path).absolute? WDA.post(path, body: body.to_json, timeout: timeout) else WDA.post(@url + path, body: body.to_json, timeout: timeout) end end
# File lib/wda_lib.rb, line 113 def set_wait(timeout = nil) if timeout.nil? @timeout = @default_timeout elsif timeout < 1 @timeout = 1 else @timeout = timeout.to_i end return @timeout end
Swipe on an element with its id and position @param fromX [Integer], toX [Integer], fromY [Integer], toY [Integer]
# File lib/wda_lib/element.rb, line 174 def swipe(fromX, toX, fromY, toY) post '/wda/dragfromtoforduration', { fromX: fromX, toX: toX, fromY: fromY, toY: toY, duration: 0 } end
Tap on a given positon @param x [Integer], y [Integer]
# File lib/wda_lib/element.rb, line 180 def tap_on(x, y) post '/wda/tap/nil', { x: x, y: y} end
Touch and hold on for a while @param x [Double], y [Double], duration [Double] @return element uuid [String]
# File lib/wda_lib/element.rb, line 193 def touch_hold(x, y, duration) client.post '/wda/touchAndHold', { x: x, y: y, duration: duration } end
@return width, height
# File lib/wda_lib/element.rb, line 204 def window_size win_size = get('/window/size')['value'] @win_x = win_size['width'] @win_y = win_size['height'] Dimension.new(win_size['width'], win_size['height']) end