mirror of
https://github.com/mkoehnke/WKZombie.git
synced 2024-10-03 21:37:59 +03:00
Initial commit for Command Line Example
This commit is contained in:
parent
dea2e63dde
commit
4b016c48ee
@ -2,8 +2,11 @@ import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "WKZombie",
|
||||
targets: [],
|
||||
targets: [
|
||||
Target(name: "WKZombie"),
|
||||
Target(name: "Example", dependencies:["WKZombie"])
|
||||
],
|
||||
dependencies: [
|
||||
.Package(url: "https://github.com/mkoehnke/hpple.git", Version(0,2,2))
|
||||
.Package(url: "https://github.com/mkoehnke/hpple.git", Version(0,2,2))
|
||||
]
|
||||
)
|
||||
|
51
Sources/Example/main.swift
Normal file
51
Sources/Example/main.swift
Normal file
@ -0,0 +1,51 @@
|
||||
import Foundation
|
||||
import WKZombie
|
||||
|
||||
let url = URL(string: "https://developer.apple.com/membercenter/index.action")!
|
||||
let arguments = CommandLine.arguments
|
||||
let user = arguments[1]
|
||||
let password = arguments[2]
|
||||
var shouldKeepRunning = true
|
||||
|
||||
func handleResult(_ result: Result<[HTMLTableRow]>) {
|
||||
shouldKeepRunning = false
|
||||
switch result {
|
||||
case .success(let value): handleSuccess(result: value)
|
||||
case .error(let error): handleError(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
func handleSuccess(result: [HTMLTableRow]?) {
|
||||
print("\n")
|
||||
print("PROVISIONING PROFILES:")
|
||||
print("======================")
|
||||
|
||||
if let columns = result?.flatMap({ $0.columns?.first }) {
|
||||
for column in columns {
|
||||
if let element = column.children()?.first as HTMLElement?, let text = element.text {
|
||||
print(text)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print("Nothing found.")
|
||||
}
|
||||
}
|
||||
|
||||
func handleError(error: ActionError) {
|
||||
print(error)
|
||||
}
|
||||
|
||||
open(url)
|
||||
>>> get(by: .id("accountname"))
|
||||
>>> setAttribute("value", value: user)
|
||||
>>> get(by: .id("accountpassword"))
|
||||
>>> setAttribute("value", value: password)
|
||||
>>> get(by: .name("form2"))
|
||||
>>> submit(then: .wait(2.0))
|
||||
>>> get(by: .contains("href", "/account/"))
|
||||
>>> click(then: .wait(2.5))
|
||||
>>> getAll(by: .contains("class", "row-"))
|
||||
=== handleResult
|
||||
|
||||
let theRL = RunLoop.current
|
||||
while shouldKeepRunning && theRL.run(mode: .defaultRunLoopMode, before: .distantFuture) { }
|
Loading…
Reference in New Issue
Block a user