Erik是一款基于WebKit的无界面浏览器,可用于功能函数的测试,使用JavaScript对网页进行操作访问。
示例(使用Google搜索):
let url = NSURL(string:"https://www.google.com")! let value = "Erik The Phantom of Opera" // visit var future: Future<Document, NSError> = Erik.visitURLFuture(url) // fill input field future = future.flatMap { document -> Future<Document, NSError> in if let input = document.querySelector("input[name='q']") { input["value"] = value } if let form = document.querySelector("form[name=\"f\"]") as? Form { form.submit() } return Erik.currentContentFuture() } // finally get final result as success or error future.onSuccess { document in // parse result } future.onFailure { error in print("\(error)") }