Skip to main content

Cypress Aliases Sharing Context

  • In cypress aliases, there is a topic of sharing context.
  • This is generally called because of its aliasing ability to name alias and call it via this keyword.
  • This is another method we can access the alias name from anywhere.
  • As we know aliases are accessible using the @aliasname.
  • But in the world of shared context, we can only call it by using this keyword.
  • The arrow bind used in the test steps 'it' cannot bind their own this keyword.

So thus in this situation to access the alias we use the traditional function() instead of => inside our test block.

Syntax For Alias:


Syntax For The Usage Of Shared Context:

it('test', function() {



So let us dive into a real-time example for the shared context alias.

describe('Automate AutoPract',()=>{
    before(() => {
    beforeEach(()=> {
    it('Should click POPUP',function(){


  • so here the before each hook I have named the alias selector as a popup which closes the popup, as soon as the website loads up.
  • As we discussed we are using the function() bind to invoke this keyword.
  • So normally this keyword will call up the alias instead of @ and proceeds to execute the test.
Submitted by arilio666 on October 20, 2021

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.