Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use nightmare

Shulou Source: shulou.com Published: 2022-06-02 15:50:10 10月03日 Update

This article mainly explains "how to use nightmare". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use nightmare.

Today we will introduce an automated test suite called nightmare, which is a test framework based on phantomjs, a set of highlevelAPI encapsulated for test applications based on phantomjs. Its API is goto,refresh,click,type... Simple and commonly used e2e test action encapsulation, which makes its semantics clear and concise.

Install nightmare:

Npminstallnightmare

Let's compare nightmare with remote phantomjs:

The code of the original phantomjs:

Phantom.create (function (ph) {

Ph.createPage (function (page) {

Page.open ('http://yahoo.com',function(status){

Page.evaluate (function () {

Varel=

Document.querySelector ('input [title = "Search"]')

El.value='githubnightmare'

}, function (result) {

Page.evaluate (function () {

Varel=document.querySelector ('.searchsubmit')

Varevent=document.createEvent ('MouseEvent')

Event.initEvent ('click',true,false)

El.dispatchEvent (event)

}, function (result) {

Ph.exit ()

})

})

})

})

})

Nightmare Code:

NewNightmare ()

.goto ('http://yahoo.com')

.type ('input [title = "Search"]', 'githubnightmare')

.click ('.searchsubmit')

.run ()

Thank you for your reading, the above is the content of "how to use nightmare", after the study of this article, I believe you have a deeper understanding of how to use nightmare, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Testing learning code content encapsulation brevity action heaven suite that is commonly used ideas situations articles more frameworks knowledge knowledge points articles semantics Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux NVidia Shulou Technology vpn MySQL