Part 17: Cypress E2E Web Automation | How To Create Custom commands
Вставка
- Опубліковано 15 жов 2024
- #cypress#automation#e2etesting#customCommands
Topics:
-------
1) Create new custom commands
2) Overwrite existing commands
3) How to use custom commands in the test scripts
#########################
Udemy Courses:
#########################
Manual Testing+Agile with Jira Tool
**********************************
► shorturl.at/xNXZ4
Selenium with Java+Cucumber
********************************
► shorturl.at/aIKMW
Selenium with Python & PyTest
********************************
► shorturl.at/ELW09
Selenium with python using Robot framework
****************************************
► shorturl.at/bcDPZ
API Testing(Postman, RestAssured & SoapUI)
*****************************************
► shorturl.at/uAWY7
Web & API Automation using Cypress with Javascript
********************************************
► rb.gy/4uum2n
Playwright with Javascript
**************************
► shorturl.at/gALZ1
Jmeter-Performance Testing
************************
► rb.gy/ocj7r2
SDET Essencials(Full Stack QA)
*************************
► rb.gy/hlnf2v
Appium-Mobile Automation Testing
************************************
► rb.gy/wmzv64
Java Collections
*****************
► bit.ly/3S66ezE
Python Programming
*********************
► urlis.net/gdsf...
Cucumber BDD Framework
***************************
► bit.ly/3F7d69r
Protractor with Javascript
***************************
► urlis.net/4udd...
####################################
UA-cam Playlists:
####################################
Manual Testing & Agile
***********************
► bit.ly/3ujvaYa
► bit.ly/3OYzxQj
SQL
*************************
► bit.ly/3R6XjeG
► bit.ly/3nE0a1s
► bit.ly/3IeKuuJ
linux & Shell Scripting
**********************
► bit.ly/3up1Z6a
► bit.ly/3nzvGxx
Java
**********************
► bit.ly/3R9QfOs
► bit.ly/3AoRMKM
► bit.ly/3IbTTDn
► bit.ly/3ybXInv
► bit.ly/3yCoHdw
Selenium With Java+Cucumber
********************************
► bit.ly/3P2FMm4
► bit.ly/3yhiIt4
► bit.ly/3uokzet
► bit.ly/3a7XIND
► bit.ly/3umN2S9
► bit.ly/3aar7GW
► bit.ly/3y9kD2S
► bit.ly/3uhLskn
Python
********************************
► bit.ly/3agNgU0
► bit.ly/3NJNnoy
► bit.ly/2CTQ4mR
► bit.ly/3OIYWh1
Selenium With Python,Pytest&Behave
***************************************
► bit.ly/3OHHoC9
► bit.ly/3IeNLdv
► bit.ly/2J4tPeT
► bit.ly/3ydSkAq
Selenium With Python Using Robert Framework
(Web&API Testing)
*************************************************
► bit.ly/3nUvlpr
► bit.ly/3nUvE3z
API Testing (Postman,SoapUi,&Rest Assured)
**********************************************
► bit.ly/3OXacWY
► bit.ly/3yh0UhE
► bit.ly/3nC9DWQ
► bit.ly/3yGfhNS
► bit.ly/3OJa11H
► bit.ly/3P2slCC
Mobile App Testing Appium
****************************
► bit.ly/3Al49HG
Performance Testing Jmeter
*******************************
► bit.ly/3nz4fE7
Maven,Jenkins,Git,Github,CI/CD
*******************************
► bit.ly/3P16HPj
► bit.ly/3yhlUVA
► bit.ly/3afYfwT
► bit.ly/3yGzweG
► bit.ly/3yF73Ws
► bit.ly/3NCOmH7
SQL,DB Testing&ETL,Bigdata
*******************************
► bit.ly/3NKOcNY
► bit.ly/3OVpDyI
► bit.ly/3NEvUy0
► bit.ly/3IryxlT
► bit.ly/3RkWBLh
JavaScript Based Automation Tools
********************************
► bit.ly/3nUx51X
► bit.ly/3AqI6Q0
► bit.ly/3yeurbT
► bit.ly/3ujzpTK
Selector Hub Tools
********************
►rb.gy/h3h424
GraphQL
******************
► rb.gy/sj3gys
Cypress API Testing
********************
► shorturl.at/fjKPX
Cypress Web Testing
**********************
► shorturl.at/agjlK
Playwright with Javascipt
*********************
► shorturl.at/adSTY
#CypressAutomation
#E2EWebTesting
#CustomCommands
#UA-camAutomation
#WebTestingSolutions
#AutomateUA-cam
#CypressFramework
#WebAutomationTools
#YTChannelAutomation
#E2ETestingFramework
#CypressTestCases
#CustomCypressCommands
#UA-camChannelGrowth
#WebAppAutomation
#CypressTesting
#UA-camContentAutomation
#AutomateWebTesting
#CypressTipsAndTricks
#YTChannelManagement
#EndToEndTesting
#CypressExtensions
#UA-camMarketingAutomation
#WebTestingBestPractices
#CypressTestAutomation
#UA-camVideoAutomation
#WebAppTesting
#CypressJavaScript
#YTChannelGrowthHacks
#UIAutomation
#CypressCustomization
#UA-camSEOAutomation
#CypressTestingFramework
#WebAutomationJourney
#CypressTestingTips
#YTChannelEngagement
#AutomatedTesting
#CypressCommandsTutorial
#UA-camAnalyticsAutomation
#CypressAutomationTricks
#YTChannelMonetization
#ContinuousTesting
#CypressWebTesting
#UA-camAlgorithmsAutomation
Thx Sir Pavan, I am very grateful for your videos!
Welcome
now this works
Cypress.Commands.overwriteQuery(
"contains",
function (contains, filter, text, userOptions = {}) {
// This is parameter resolution from Cypress v12.7.0 source
if (Cypress._.isRegExp(text)) {
// .contains(filter, text)
// Do nothing
} else if (Cypress._.isObject(text)) {
// .contains(text, userOptions)
userOptions = text
text = filter
filter = ''
} else if (Cypress._.isUndefined(text)) {
// .contains(text)
text = filter
filter = ''
}
userOptions.matchCase = false;
let contains0 = contains.bind(this) // this line fixes the error
return contains0(filter, text, userOptions)
}
)
Thanks a lot, It is working
Thank you, sir!
Thanku
yes it is working thank you
Thank you, this works
this commands has crushed my cypress app.
same
@Jaskierify
1 month ago
Unfortunately last two custom commands (overwrite/login app) result in cypress error: Cannot read properties of undefined (reading 'hasPreviouslyLinkedCommand')
I did exactly the same way as presented in the video.
i am also facing this error could you help me resolve
You can add this in the it block at the top: Cypress.on('uncaught:exception', (err, runnable) => {
if (err.message.includes('Cannot read properties of undefined')) {
return false;
}
return true;
});
Hello Sir
I am getting errors for overwriting contains() command
CypressError
The following error originated from your test code, not from Cypress.
> Cannot overwrite the contains the query. Queries cannot be overwritten.
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error with any specific test.
We dynamically generated a new test to display this failure. Learn more
Hoping for your reply soon!
I have the same error.
0 seconds ago
try to comment un used custom commands in commands.js@@JoolieEm
I am getting this error
Argument of type '(a: string, b: any, c: string) => void' is not assignable to parameter of type 'CommandFn'.
TQ,Sir, nice expansion,please provide Cypress meterial
hi sir while accessing custom commands in main file im getting a type erroe ( TypeError: cy.login is not a function ) can you please help me
Thank you so much sir
Welcome
Thanks Sir for great video. I am getting issue with over writing command contains even through I wrote the code like you. I got the message following error:
An uncaught error was detected outside of a testfailed
No commands were issued in this test.
CypressError
The following error originated from your test code, not from Cypress.
> Cannot overwite the contains query. Queries cannot be overwritten.
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error to any specific test.
We dynamically generated a new test to display this failure
Hoping for your reply soon!
facing same issue
we need to use 10.7 to make this work
I'm also facing same issue
Hey. Try to use this command for the overwrite 'contains' command:
// -- The custom command for overwriting contains() method --
Cypress.Commands.overwrite("contains", function (contains, filter, text, userOptions = {}) {
if (Cypress._.isRegExp(text)) {
// .contains(filter, text)
// Do nothing
} else if (Cypress._.isObject(text)) {
// .contains(text, userOptions)
userOptions = text
text = filter
filter = ''
} else if (Cypress._.isUndefined(text)) {
// .contains(text)
text = filter
filter = ''
}
userOptions.matchCase = false;
let contains0 = contains.bind(this)
return contains0(filter, text, userOptions)
}
)
I need your help, i writing similar command to get value from textbox by return value but not success, can you help me
Sir now cypress shows error for that over write - ut says cannot overwrite the contains query.querries can be overwritten with with
Cypress.Commands.overwriteQuerry().
Thank sir! Nice video❤️
Welcome 👍
Unfortunately last two custom commands (overwrite/login app) result in cypress error: Cannot read properties of undefined (reading 'hasPreviouslyLinkedCommand')
I did exactly the same way as presented in the video.
Try to use this code:
// -- The custom command for overwriting contains() method --
Cypress.Commands.overwrite("contains", function (contains, filter, text, userOptions = {}) {
if (Cypress._.isRegExp(text)) {
// .contains(filter, text)
// Do nothing
} else if (Cypress._.isObject(text)) {
// .contains(text, userOptions)
userOptions = text
text = filter
filter = ''
} else if (Cypress._.isUndefined(text)) {
// .contains(text)
text = filter
filter = ''
}
userOptions.matchCase = false;
let contains0 = contains.bind(this)
return contains0(filter, text, userOptions)
}
)
@@jaminDNB Thank you Ivan :)
At time 34:41, you have added cy.wait(3000). What is the point of adding static wait when cypress supports autowait and auto synchronisation?
Hello Sir
I am getting error for over writing contains() command
CypressError
The following error originated from your test code, not from Cypress.
> Cannot overwite the contains query. Queries cannot be overwritten.
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error to any specific test.
We dynamically generated a new test to display this failure.Learn more
try to comment un used custom commands in commands.js
Video is not clear sir