Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week-1 task Completed #122

Merged
merged 29 commits into from
Jul 16, 2021
Merged

Week-1 task Completed #122

merged 29 commits into from
Jul 16, 2021

Conversation

shailesh1028
Copy link
Contributor

Week-1 Task

Layout testing: Created test to check the different version/layout of preview based on the API data. This will help when we run the tests on different viewports.
Apart from this, added an event test that includes hovering and clicking over the span to generate the preview.
Error Found: The close button does not work in all other modes except in Standard mode.


beforeEach('Open the English Page', () => {
cy.navigateToHomePage('/articles/english.html')
cy.wait(2000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never use waits unless absolutely needed, which is not the case here, delete them all.
cypress handles waits automatically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wait is required in my system as it takes time to load the changes. I have removed it while pushing the current changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for slow networks u can use
https://docs.cypress.io/guides/references/configuration#Timeouts
in the configuration file cypress.json to increase the timeout




Cypress.on('uncaught:exception', (err, runnable) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is required when the preview reacts unexpectedly due to some issues(mainly connectivity issues as it delays the response ) so this command prevents the cypress test to fail due to the errors generated from our app.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a test should always fail whenever something goes wrong, this shouldn't be used

const lang = tag.attr('lang')

preview.Body().should('be.visible')
.and('have.class','wikipediapreview-body-disambiguation')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be in a page-object, no selectors here that might be useful for other tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do understand your concern. But those classes are added during runtime to render the different layouts. Thereby it is necessary to check whether they are added or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so don't use commands.js for this, use page-objects elements that are only used searched for when needed.
avoid using commands.js for specific test logic, only when it's for actions on the app that always use present elements like we do here - https://github.com/wikimedia/wikipedia-kaios/blob/main/cypress/support/commands.js

u can delete most of ur commands.js code and move it to test and page-object files

// Custom Command to check the Preview in Offline Mode
Cypress.Commands.add('CheckPreviewOffline' , () =>{

preview.Preview().should('be.visible')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tabs and spaces, format the code correctly

@jpita
Copy link
Contributor

jpita commented Jun 21, 2021

  1. run npx eslint cypress --fix
  2. install the needed dependencies
  3. put this on the .eslintrc.js file
module.exports = {
  env: {
    browser: true,
    es6: true
  },
  extends: [
    'eslint:recommended',
    'wikimedia/client',
    "plugin:cypress/recommended"
  ],
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly',
    require: true
  },
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: 'module'
  },
  rules: {
    semi: [2, "never"],
    'no-nonoctal-decimal-escape': 'off',
    "no-only-tests/no-only-tests": "error",
    "cypress/no-unnecessary-waiting": "warn"
  },
  "plugins": [
    "cypress",
    "no-only-tests"
  ],
}

  1. run npx eslint cypress --fix
  2. fix the issues

@jpita
Copy link
Contributor

jpita commented Jun 24, 2021

did u do steps 4 and 5 from my previous comment?


// Wikipedia Preview Footer
getFooter() {
return cy.get( 'div.wikipediapreview' ).find( ' div.wikipediapreview-footer' )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not do
cy.get('div.wikipediapreview-footer')

only instead of get+find?

@jpita
Copy link
Contributor

jpita commented Jun 28, 2021

you don't need the check.js class, delete it and add the methods to check for elements inside the preview page object.
check what we did in the kaios code https://github.com/wikimedia/wikipedia-kaios/tree/main/cypress/page-objects.

when u have a page object class, you can create a method inside that page object to check for the presence of the elements.
the same way u would have a login method inside the login page object.
the purpose is to keep the code organised and easy to change when there's a selector change or a UI change.
u can read up on page-object
https://www.guru99.com/page-object-model-pom-page-factory-in-selenium-ultimate-guide.html
https://www.browserstack.com/guide/page-object-model-in-selenium

if u don't understand what I mean we can talk about this during a meeting.

P.S.: similarly to the kaios files, ur page objects need to end in page.js. If u have some files that are not page-objects please remove them from the folder and create a different one, for example helpers

@jpita jpita merged commit e0912eb into wikimedia:gsoc-first-test Jul 16, 2021
jpita added a commit that referenced this pull request Jul 21, 2021
* Week-1 task Completed (#122)

* Week-1 task Completed

* PR Review changes

* PR Review Changes

* PR Review changes

* Layout Testing Changes

* Offline Testing Functions

* Delete expand-spec.js

* add eslint package and run eslint

* small fix, timeout increase

* skiping failing tests

* Update config.yml

add cypress tests

* PR Review Changes added

* Removed Waits

* Changes check Preview function to objects

* Changes check Preview function to objects

* check.js Removed and helpers folder created for network.js

* Added page.js in Page-Object

* final changes

* bump cypress version, make code more clear

* package.lock

* package.json changed

* Package.json Changed

* package.json changed

* config.yml changed

* adding waits

* adding waits

Co-authored-by: Gabriel Pita <dvpita@gmail.com>

* package lock

* change circleci config

* remove useless comments

* linter fixes

* fix

* fix

* eslint

* fix comments

Co-authored-by: Shailesh <41967175+shailesh1028@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants