Page MenuHomePhabricator

Micro-task: Create a simple test using Cypress
Closed, ResolvedPublic

Description

Pick a simple test from mediawiki/core, for example User should be able to create account and implement it using Cypress. Feel free to pick any other test, this is just an example.

webdriverio implementation:

https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/master/tests/selenium/specs/user.js#21

describe( 'User', function () {
	it( 'should be able to create account', function () {
		// create
		CreateAccountPage.createAccount( username, password );
		// check
		assert.strictEqual( CreateAccountPage.heading.getText(), `Welcome, ${username}!` );
	} );
} );

https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/master/tests/selenium/pageobjects/createaccount.page.js

class CreateAccountPage extends Page {
	get username() { return $( '#wpName2' ); }
	get password() { return $( '#wpPassword2' ); }
	get confirmPassword() { return $( '#wpRetype' ); }
	get create() { return $( '#wpCreateaccount' ); }
	get heading() { return $( '#firstHeading' ); }
	open() {
		super.openTitle( 'Special:CreateAccount' );
	}
	createAccount( username, password ) {
		this.open();
		this.username.setValue( username );
		this.password.setValue( password );
		this.confirmPassword.setValue( password );
		this.create.click();
	}
}

Steps:

  • open Special:CreateAccount page
  • populate required fileds with random strings
  • click Create your account button

Assertions:

  • check that text Welcome, ${username}! appears on the page

For more information on page object pattern see (draft) page https://www.mediawiki.org/wiki/Selenium/Explanation/Page_object_pattern

Students:

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMar 21 2020, 10:19 AM
zeljkofilipin updated the task description. (Show Details)
Soham added a subscriber: Soham.EditedMar 21 2020, 1:37 PM

@zeljkofilipin, I am a bit lost here. Do we have to clone "git clone ssh://gerrit.wikimedia.org:29418/mediawiki/core" ?

@AlQaholic007: See the line "Pick a simple test from mediawiki/core" in the task description and follow https://www.mediawiki.org/wiki/Gerrit/Tutorial

In T248220#5988939, @AlQaholic007 wrote:

@zeljkofilipin, I am a bit lost here. Do we have to clone "git clone ssh://gerrit.wikimedia.org:29418/mediawiki/core" ?

I've updated the task description. Before this task, you have to do T248016: Micro-task: Run Selenium tests on your machine. Cloning mediawiki/core is the part of that task.

Soham added a comment.Mar 21 2020, 2:59 PM

@AlQaholic007: See the line "Pick a simple test from mediawiki/core" in the task description and follow https://www.mediawiki.org/wiki/Gerrit/Tutorial

Do i have to work with this setup first? I'm sorry for asking silly questions but I'm new to Gerrit. For the earlier micro-task, what i did was fork wikimedia/mediawiki repo and then clone it and set up on my local machine

@AlQaholic007 it's not a silly question. It's normal to be confused when you have to work with new tools. Correct, you have to clone mediawiki/core on your machine. I will create another micro-task that explains the steps.

@zeljkofilipin I am actually struggling to select elements with multiple class names and couldn't find any documentation or stack overflow to suggest how this could be accomplished with Cypress. Are you aware if cypress has any XPath support like WebDriverIO does?

Jpita added a comment.Mar 24 2020, 2:52 PM

@AlQaholic007 https://docs.cypress.io/api/commands/get.html#Alias
if you still can't find the elements after reading this, let me know and I'll show you how.

Soham added a comment.EditedMar 24 2020, 2:54 PM

@Jpita thanks a tonne...Is there a good reference to XPath like usage in Cypress. I actually read theres a npm package called cypress-xpath which exposes this functionality but based on downloads Im a bit skeptical. What I am essentially trying to accomplish is find an element that has 3 class names and an attribute with certain value

Jpita added a comment.Mar 24 2020, 3:21 PM

@AlQaholic007
can you paste here the HTML of the element?

usually for many class names such as <div class="name1 name2" I use css with a . instead of spaces, cy.get('div.name1.name2').

I used to use a lot of xpath with selenium but stopped using it with cypress, it has better support for css selectors.

For an attribute with a certain value you can use:
cy.get('div[attribute="attributeValue"]')

Soham added a comment.Mar 24 2020, 3:25 PM

@AlQaholic007
can you paste here the HTML of the element?

usually for many class names such as <div class="name1 name2" I use css with a . instead of spaces, cy.get('div.name1.name2').

I used to use a lot of xpath with selenium but stopped using it with cypress, it has better support for css selectors.

For an attribute with a certain value you can use:
cy.get('div[attribute="attributeValue"]')

Say for example we have an element <button data-href="some value" class=" c1 c2 c3 "></button> and there are multiple instances of such elements but i want to pick one with certain value on data href

Jpita added a comment.Mar 24 2020, 3:28 PM

@AlQaholic007
cy.get('button[data-href="some value"]')

this should work if the value of data-href is unique

Soham added a comment.Mar 24 2020, 3:30 PM

@Jpita oops so silly of me to not realize the hint you gave earlier. I'm still getting used to not using XPath. So sorry🙈

@zeljkofilipin just committed my submission for this task. @Jpita I am struggling with environment variables in cypress. Turns out cypress doesnt detect process.env and Cypress.env didnt work for me. I set up the env variables in cypress/plugins/index.js as recommended in the documentation but that did'nt work either. How should we go about to set the browser configuration variables in cypress like username and password for API?

@AlQaholic007 it's hard to debug remotely. 😁 Please push your changes to Gerrit, so @Jpita and I can try them on our machine.

If you're getting error messages while running tests, please copy/paste all relevant terminal output here. Creating a separate task might be a good idea, so we can resolve it when the problem is fixed.

Soham added a comment.EditedMar 25 2020, 2:49 PM

@AlQaholic007 it's hard to debug remotely. 😁 Please push your changes to Gerrit, so @Jpita and I can try them on our machine.

If you're getting error messages while running tests, please copy/paste all relevant terminal output here. Creating a separate task might be a good idea, so we can resolve it when the problem is fixed.

Sorry @zeljkofilipin my bad I forgot to add relevant images. However I found out a way around and committed the new code just few minutes back. Will add you for review. Also, cypress is so much more faster than WebDriverIO🙌🏻

Change 583353 had a related patch set uploaded (by Zfilipin; owner: AlQaholic007):
[mediawiki/core@master] modified cypress tests

https://gerrit.wikimedia.org/r/583353

Dinp2 added a subscriber: Dinp2.Mar 26 2020, 5:10 PM

Change 584903 had a related patch set uploaded (by Zfilipin; owner: AlQaholic007):
[mediawiki/core@master] cypress tests

https://gerrit.wikimedia.org/r/584903

Change 583310 had a related patch set uploaded (by Zfilipin; owner: AlQaholic007):
[mediawiki/core@master] added preliminary test in cypress

https://gerrit.wikimedia.org/r/583310

Change 583311 had a related patch set uploaded (by Zfilipin; owner: AlQaholic007):
[mediawiki/core@master] added preliminary test in cypress

https://gerrit.wikimedia.org/r/583311

Change 583352 had a related patch set uploaded (by Zfilipin; owner: AlQaholic007):
[mediawiki/core@master] modified cypress tests

https://gerrit.wikimedia.org/r/583352

Change 584966 had a related patch set uploaded (by Dinp2; owner: Dinp2):
[mediawiki/core@master] Simple cypress test to create user account

https://gerrit.wikimedia.org/r/584966

Change 583353 abandoned by AlQaholic007:
modified cypress tests

https://gerrit.wikimedia.org/r/583353

Change 583352 abandoned by AlQaholic007:
modified cypress tests

https://gerrit.wikimedia.org/r/583352

Change 583310 abandoned by AlQaholic007:
added preliminary test in cypress

https://gerrit.wikimedia.org/r/583310

Change 583311 abandoned by AlQaholic007:
added preliminary test in cypress

https://gerrit.wikimedia.org/r/583311

Change 584903 had a related patch set uploaded (by AlQaholic007; owner: AlQaholic007):
[mediawiki/core@master] Implemented cypress test for testing account creation

https://gerrit.wikimedia.org/r/584903

Dinp2 removed a subscriber: Dinp2.Apr 3 2020, 11:07 AM

Change 584966 abandoned by Dinp2:
Simple cypress test to create user account

https://gerrit.wikimedia.org/r/584966

zeljkofilipin updated the task description. (Show Details)Apr 3 2020, 6:04 PM
zeljkofilipin added a subscriber: Gbahdeyboh.
zeljkofilipin updated the task description. (Show Details)Apr 3 2020, 6:09 PM

Change 587578 had a related patch set uploaded (by Gbahdeyboh; owner: Gbahdeyboh):
[mediawiki/core@master] Micro-task: Create a simple test using Cypress

https://gerrit.wikimedia.org/r/587578

Change 587578 had a related patch set uploaded (by Gbahdeyboh; owner: Gbahdeyboh):
[mediawiki/core@master] Micro-task: Create a simple test using Cypress

https://gerrit.wikimedia.org/r/587578

Change 589405 had a related patch set uploaded (by Gbahdeyboh; owner: Gbahdeyboh):
[mediawiki/core@master] Micro-task: Create a simple test using Cypress

https://gerrit.wikimedia.org/r/589405

Change 589405 abandoned by Gbahdeyboh:
Micro-task: Create a simple test using Cypress

Reason:
This is supposed to be patch 25 on T230729. I'm not sure it's being uploaded to an entirely new patch

https://gerrit.wikimedia.org/r/589405

Change 589409 had a related patch set uploaded (by Gbahdeyboh; owner: Gbahdeyboh):
[mediawiki/core@master] Micro-task: Create a simple test using Cypress

https://gerrit.wikimedia.org/r/589409

Change 589409 abandoned by Gbahdeyboh:
Micro-task: Create a simple test using Cypress

https://gerrit.wikimedia.org/r/589409

Change 589405 restored by Gbahdeyboh:
Micro-task: Create a simple test using Cypress

https://gerrit.wikimedia.org/r/589405

Change 589405 abandoned by Gbahdeyboh:
Micro-task: Create a simple test using Cypress

https://gerrit.wikimedia.org/r/589405

Change 587578 abandoned by Zfilipin:
Micro-task: Create a simple test using Cypress

Reason:
GSoC application period is finished. Let's continue collaborating on https://gerrit.wikimedia.org/r/c/mediawiki/core/ /584903

https://gerrit.wikimedia.org/r/587578

Change 597125 had a related patch set uploaded (by AlQaholic007; owner: AlQaholic007):
[mediawiki/core@master] Cypress: Setup Cypress and configure ESLint for Cypress.

https://gerrit.wikimedia.org/r/597125

Change 598253 had a related patch set uploaded (by AlQaholic007; owner: AlQaholic007):
[mediawiki/core@master] Cypress: Implement a simple test to check for default main page heading

https://gerrit.wikimedia.org/r/598253

zeljkofilipin closed this task as Resolved.May 25 2020, 2:06 PM
zeljkofilipin claimed this task.
zeljkofilipin updated the task description. (Show Details)

Change 584903 abandoned by AlQaholic007:
GSOC Microtask: Implemented cypress test for testing account creation

Reason:
GSOC application period is over

https://gerrit.wikimedia.org/r/584903

Change 599937 had a related patch set uploaded (by AlQaholic007; owner: AlQaholic007):
[mediawiki/core@master] WIP Cypress: Implement test for checking Admin login

https://gerrit.wikimedia.org/r/599937

Change 600406 had a related patch set uploaded (by AlQaholic007; owner: AlQaholic007):
[mediawiki/core@master] WIP Cypress: Implement test to check for account creation

https://gerrit.wikimedia.org/r/600406