XCUITEST - 由Xcode 8打破的pressForDuration?

时间:2016-09-07 23:55:56

标签: ios xcode

我已经在iOS应用程序中进行了一些UI测试,这些测试曾经有效,但现在已经失败了。我刚刚安装了Xcode 8的GM版本。这是一个典型的代码片段。

import requests
import pprint
import threading

def fetch_ev(index, url):  # index parameter added
    response = requests.get(url)
    response.raise_for_status()
    data = response.json()
    ev_single = data['quoteSummary']['result'][0][
                     'defaultKeyStatistics']['enterpriseValue']['raw']
    with ev_array_lock:
        ev_array[index] = ev_single  # store enterprise value obtained

tickers = ['aapl', 'googl', 'nvda']
ev_array = [None] * len(tickers)  # preallocate to hold results
ev_array_lock = threading.RLock()  # to synchronize concurrent array access
urls = ['https://query2.finance.yahoo.com/v10/finance/quoteSummary/{}'
        '?formatted=true&crumb=8ldhetOu7RJ&lang=en-US&region=US'
        '&modules=defaultKeyStatistics%2CfinancialData%2CcalendarEvents'
        '&corsDomain=finance.yahoo.com'.format(symbol)
           for symbol in tickers]
threads = [threading.Thread(target=fetch_ev, args=(i, url))
                for i, url in enumerate(urls)]  # activities to obtain ev's

for thread in threads:
    thread.start()
for thread in threads:
    thread.join()
pprint.pprint(dict(zip(tickers, ev_array)))

有问题的UISwitch最初是关闭的。我在开关的左半部分得到一个坐标,在右半部分找到另一个坐标。

之前,这将成功关闭开关。但是现在pressForDuration没有效果。

有关如何解决这个问题的想法吗?

1 个答案:

答案 0 :(得分:0)

我也遇到过这个问题,但只是横向问题。我使用以下扩展名作为解决方法。

// fix coordinate for landscape bug in Xcode Version 8.0 (8A218a)
extension XCUICoordinate {

    func fix() -> XCUICoordinate {
        let window = XCUIApplication().windows.element(boundBy: 0)
        let baseCoordinate = window.coordinate(withNormalizedOffset: CGVector(dx: 0.0, dy: 0.0))
        switch XCUIDevice.shared().orientation  {
        case .landscapeRight:
            return baseCoordinate.withOffset(CGVector(dx: self.screenPoint.y, dy: window.frame.width - self.screenPoint.x))
        case .landscapeLeft:
            return baseCoordinate.withOffset(CGVector(dx: window.frame.height - self.screenPoint.y, dy: self.screenPoint.x))
        default:
            return self
        }
    }
}