CypressAPI of cy.visit ()

 

visit

 

effect:

Access a remote URL.

(Suggestion: use before setting  baseUrl)

grammar:

cy.visit(url)
cy.visit(url, options)
cy.visit(options)

use:

cy.visit ( 'HTTP: // localhost: 3000')     // generate remote page window

parameter:

 > url (String)

To access the URL. ( If you set baseUrlwill be used baseUrlto configure the url as a prefix )

 > options (Object)

Pass a object to control options for this method.

Options:

Options

default

description

url

null

To access the URL, the urlsame behavior parameters.

method

GET

For use in accessing the HTTP method, it may be GETor POST.

body

null

And POSTalong with the request sent by the optional body.

If it is a string, to pass intact.

If it is an object to be encoded with a string 消息(header Content-Type: application/x-www-urlencoded)transmitted together.  

headers

{}

HTTP header name mapping object value to be transmitted along with the request.

Note: headers Only for the initial cy.visit()request, but not for all subsequent requests.

log

true

Displays the command in the command log

auth

null

Add basic authorization header

failOnStatusCode

true

When the response code is not 2xxand3xx时是否报错

onBeforeLoad

function

Called before the page loads all the resources

onLoad

function

After your page load event triggers its call

retryOnStatusCodeFailure  

false

When the status code if the error is automatically retry

retryOnNetworkFailure

true

When the network errors are automatically retried

timeout

pageLoadTimeout  

Page load timeout in milliseconds.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

example:

// set the timeout 
cy.visit ( '/ index.html', {timeout: 30000 }) 

// add authentication (. 1) 
cy.visit ( 'https://www.acme.com/' , { 
  the auth: { 
    username: 'Wile' , 
    password: 'Coyote' 
  } 
}) 

// add authentication (2) 
cy.visit ( 'HTTPS: // Wile: [email protected]' ) 

// page finished loading after all resources call the function 
cy.visit ( 'HTTP: // localhost: 3000 / # Dashboard' , { 
  : (contentWindow) onBeforeLoad => {
     // contentWindow window object is remote pages 
  } 
}) 

// call the function after the trigger event is loaded 
cy. visit ( 'http: // localhost: 3000 / # / users', { 
  The onLoad: (contentWindow) => {
     // contentWindow window object is remote page 
    IF (contentWindow.angular) {
       // events 
    } 
  } 
}) 

// send a post request 
cy.visit ({ 
  URL: 'HTTP: / / localhost: 3000 / CGI-bin / newsletterSignup ' , 
  Method: ' the POST ' , 
  body: { 
    name: ' George P. Burdell ' , 
    In Email: ' [email protected] ' 
  } 
})

 

 

Guess you like

Origin www.cnblogs.com/leozhanggg/p/10980791.html