All Projects → phimage → Erik

phimage / Erik

Licence: mit
Erik is an headless browser based on WebKit. An headless browser allow to run functional tests, to access and manipulate webpages using javascript.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Erik

Mockito
HTTP mocking for Rust!
Stars: ✭ 335 (-24.72%)
Mutual labels:  test
Twist
Declarative JavaScript Testing.
Stars: ✭ 379 (-14.83%)
Mutual labels:  test
Bach
Bach Testing Framework
Stars: ✭ 392 (-11.91%)
Mutual labels:  test
Expynent
A library that provides regular expression patterns. If you hate to write regular expressions, then expynent can help you.
Stars: ✭ 350 (-21.35%)
Mutual labels:  test
Unity Actions
Github actions for testing and building Unity projects
Stars: ✭ 358 (-19.55%)
Mutual labels:  test
Java Testdata Generator
使用Java实现的各种测试数据的随机生成工具,包括身份证号码,银行卡号,姓名,手机号等
Stars: ✭ 379 (-14.83%)
Mutual labels:  test
Uiautomator2
Android Uiautomator2 Python Wrapper
Stars: ✭ 4,080 (+816.85%)
Mutual labels:  test
Electrino
Desktop runtime for apps built on web technologies, using the system's own web browser engine
Stars: ✭ 4,197 (+843.15%)
Mutual labels:  webkit
Mimic
Seamless client side mocking
Stars: ✭ 380 (-14.61%)
Mutual labels:  test
Testfx
MSTest V2 framework and adapter
Stars: ✭ 391 (-12.13%)
Mutual labels:  test
Fakerest
Patch fetch/XMLHttpRequest to fake a REST API server in the browser, based on JSON data.
Stars: ✭ 350 (-21.35%)
Mutual labels:  test
Zora
Lightest, yet Fastest Javascript test runner for nodejs and browsers
Stars: ✭ 356 (-20%)
Mutual labels:  test
Shellspec
A full-featured BDD unit testing framework for bash, ksh, zsh, dash and all POSIX shells
Stars: ✭ 375 (-15.73%)
Mutual labels:  test
Mastermind
Man in the middle testing
Stars: ✭ 341 (-23.37%)
Mutual labels:  test
Citgm
Canary in the Gold Mine
Stars: ✭ 405 (-8.99%)
Mutual labels:  test
Webbrowser
iOS浏览器 Web Browser for iOS
Stars: ✭ 332 (-25.39%)
Mutual labels:  webkit
Enzyme
JavaScript Testing utilities for React
Stars: ✭ 19,781 (+4345.17%)
Mutual labels:  test
Tparse
CLI tool for analyzing and summarizing go test output. Pipe friendly. CI/CD friendly.
Stars: ✭ 445 (+0%)
Mutual labels:  test
Log Process Errors
Show some ❤️ to Node.js process errors
Stars: ✭ 424 (-4.72%)
Mutual labels:  test
Venom
🐍 Manage and run your integration tests with efficiency - Venom run executors (script, HTTP Request, web, imap, etc... ) and assertions
Stars: ✭ 384 (-13.71%)
Mutual labels:  test

Erik

Join the chat at https://gitter.im/phimage/Erik License Platform Language Issues CocoapodCarthage compatible

Become a Patron! Buy me a coffee

Erik is a headless browser based on WebKit and HTML parser Kanna.

An headless browser allow to run functional tests, to access and manipulate webpages using javascript.

let browser = Erik.visit(url: url) { document, error in
    // browse HTML element, click, submit form and more
}

Navigation

Go to an url

Erik.visit(url: url) { object, error in
    if let e = error {

    } else if let doc = object {
        // HTML Inspection
    }
}

How to get current url?

if let url = Erik.currentURL {..}

For multiple browsing you can create an instance of headless browser and use same functions

let browser = Erik()
browser.visitURL...

HTML Inspection

Search for nodes by CSS selector

for link in doc.querySelectorAll("a, link") {
    print(link.text)
    print(link["href"])
}

Edit first input field with name "user"

if let input = doc.querySelectorAll("input[name=\"user\"]").first {
    input["value"] = "Eric"
}

Submit a form

if let form = doc.querySelector("form[id='search']") as? Form {
    form.submit()
}

Evaluate some JavaScript

let javaScriptSource = "console.log("test");"
Erik.evaluate(javaScript:javaScriptSource) { (obj, err) -> Void in
    if let error = err {
        switch error {
            case ErikError.javaScriptError(let message):
            print(message)
            default :
            print("\(error)")
        }
    }
    else if let capturedValue = obj {
        // do something according to result
    }
}

capturedValue is the content of JavaScript variable resultErik Affect this variable in your JavaScript code.

let javaScriptSource = "console.log('test'); var resultErik = 1 + 1;"

Warning about DOM change

⚠️ All action on Dom use JavaScript and do not modify the actual Document object and its children Element.

You must use currentContent to get a refreshed Document object

Get current content

Erik.currentContent { (obj, err) -> Void in
    if let error = err {
    }
    else if let document = obj {
       // HTML Inspection
    }
}

Using Future

As an optional feature, you can use Future/Promise ( Erik use frameworks BrightFutures & Result)

Example to submit a google search

let url = NSURL(string:"https://www.google.com")!
let value = "Erik The Phantom of Opera"
// visit
var future: Future<Document, NSError> = Erik.visitFuture(url: 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)")
}

Limitation

On iOS 9 and macOS 10.11, you need to ensure you use https://, because iOS 9 and macOS 10.11 do not like apps sending or receiving data insecurely. If this something you want to override, click here to read about App Transport Security.

Links

Setup

Using cocoapods

CocoaPods is a centralized dependency manager for Objective-C and Swift. Go here to learn more.

  1. Add the project to your Podfile.

    use_frameworks!
    
    pod 'Erik'
    // or specific target
    target :test do
       pod 'Erik'
    end
    
  2. Run pod install and open the .xcworkspace file to launch Xcode.

Optional Future

Add pod 'Erik/Future' to your Podfile and run pod install.

Using carthage

Carthage is a decentralized dependency manager for Objective-C and Swift.

  1. Add the project to your Cartfile.

    github "phimage/Erik"
    

Roadmap

  • [ ] (WIP) WKWebView screenshot (webkit view privates api?)

Why Erik?

A well known headless browser is named PhantomJS and a very well known browser is Opera.

As a tribute I use Erik, firstname of the title character from Gaston Leroux's novel Le Fantôme de l'Opéra best known to English speakers as The Phantom of Opera

My name is also Erik. So egotistical to call a project using its firstname isn't it.

My only justification is that I was playing Metal Gear Solid V and the creator Hideo Kojima name appears over 100 times in the game. Coincidentally the full name of the game is Metal Gear Solid V : The Phantom Pain.

License

The MIT License. See the LICENSE file for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].