codeceptjs / CodeceptJS

Supercharged End 2 End Testing Framework for NodeJS
http://codecept.io
MIT License
4.11k stars 724 forks source link

Including PageObject must be in order #1562

Closed stychu closed 2 years ago

stychu commented 5 years ago

What are you trying to achieve?

When I have multipe pageobject I want to be able to include only specific ones

What do you get instead?

From the docs

You can include this pageobject in test by its name (defined in codecept.json). In case you created a loginPage object it should be added to list of test arguments to be included in test:

Scenario('login', (I, loginPage) => {
  loginPage.sendForm('john@doe.com','123456');
  I.see('Hello, John');
});

It seems like I must provide all pageobjects in order as they are specified in the config in order to access them.

Scenario('', (I, dashboardPage, dealPage) => { // here i want only dealPage but i must provide all.. cant we get specific ones somehow?

//config
include: {
    // PAGES
    I: './pages/steps_file.js',
    dashboardPage: './pages/dashboard.js',
    dealPage: './pages/deal.js',
    // FRAGMENTS
    modal: './fragments/modal.js',
  },
DavertMik commented 5 years ago

No idea why providing exact POs doesn't work for you...

xMutaGenx commented 5 years ago

This should work as expected, in addition I would suggest doing something like:

include: {
    I: './custom/steps_file',
    pages: './pages',
    fragments: './fragments',
  }

and have an index.js file in your pages and fragments folder, this way you don't need to update your config when you add new pages/fragments :) this would require you to move out the steps_file.js too..

kobenguyent commented 5 years ago

In my case, I just included them in the config file

    include: {
        data: './test.data.js',
        searchAddressComp: '../../test/codeceptjs/components/searchAddress.js',
        restaurantList: '../../test/codeceptjs/pages/RestaurantList',
        loginPage: '../../test/codeceptjs/pages/LoginPage',
        menuPage: '../../test/codeceptjs/pages/MenuPage',
        checkoutPage: '../../test/codeceptjs/pages/CheckoutPage',
        orderConfirmationPage: '../../test/codeceptjs/pages/orderConfirmationPage'
    },

And call them directly in test file without any injection.

Before((I) => {
    I.amOnPage('/_test');
    searchAddressComp.addressInput(searchAddress);
});

Scenario('Search a restaurant on restaurant list', async (I) => {
    const deliveryAddress = await I.grabTextFrom(restaurantList.deliveryAddress);
    expect(deliveryAddress).to.eql(searchAddress);
    restaurantList.searchRestaurant();
    I.see(data.restaurantList.testRestaurantName);
});
stychu commented 5 years ago

@xMutaGenx solution somehow works but I would love to be able to do like @PeterNgTr but I can't achieve this ;/

kobenguyent commented 5 years ago

@stychu are you using latest codeceptjs 2.0.7?

stychu commented 5 years ago

Yes @PeterNgTr

kobenguyent commented 5 years ago

@stychu are you using the same name when doing export default in your code

dashboardPage: './pages/dashboard.js',

like this

export default dashboardPage = {
...
}
stychu commented 5 years ago

I do have module.exports = {

kobenguyent commented 5 years ago

@stychu please try my approach :)

stychu commented 5 years ago

@PeterNgTr what wersion of node ure using ?

kobenguyent commented 5 years ago

@stychu 8.15

xMutaGenx commented 5 years ago

I thought we should use >=8.9.1 as per https://github.com/Codeception/CodeceptJS/blob/master/package.json#L94 @PeterNgTr

kobenguyent commented 5 years ago

yeah 8.15 is > 8.9.1 :P

xMutaGenx commented 5 years ago

Derp, sorry T_T

stychu commented 5 years ago

@PeterNgTr I guess you are also using some transpilers? Could you share your package.json?

kobenguyent commented 5 years ago
{
  "name": "test-test",
  "dependencies": {
    "babel-preset-es2015": "6.24.1",
    "babel-preset-stage-2": "6.24.1",
    "bluebird": "2.9.13",
    "brfs": "0.0.8",
    "bromote": "~0.2.1",
    "browserify": "14.4.0",
    "browserstack-automate": "^1.0.2",
    "cls-bluebird": "~1.0.0",
    "compression": "1.7.0",
    "continuation-local-storage": "^3.1.0",
    "exorcist": "0.4.0",
    "express": "^4.0.0",
    "findit": "~0.1.2",
    "ismobilejs": "~0.3.9",
    "livereload-js": "2.2.2",
    "lodash": "~2.4.1",
    "md5": "^2.0.0",
    "moment": "~2.17.0",
    "moment-timezone": "~0.5.0",
    "morgan": "1.8.2",
    "newrelic": "~4.10.0",
    "node-uuid": "^1.4.0",
    "planout": "2.0.2",
    "proxy-middleware": "~0.5.0",
    "request": "~2.81.0",
    "run-sequence": "1.1.0",
    "rx": "^2.5.0",
    "semver": "^5.3.0",
    "sha256": "^0.2.0",
    "sticky-kit": "1.1.3",
    "through2-map": "^2.0.0",
    "tiny-lr": "1.0.5",
    "uglify-js": "3.0.28",
    "underscore.string": "~2.3.3",
    "virtual-dom": "2.1.1"
  },
  "devDependencies": {
    "babel-eslint": "8.0.1",
    "babel-plugin-transform-runtime": "6.23.0",
    "babel-preset-env": "1.6.1",
    "babelify": "^7.3.0",
    "chai": "4.1.2",
    "chai-as-promised": "7.1.1",
    "chai-json-schema": "1.5.0",
    "commander": "2.13.0",
    "del": "3.0.0",
    "eslint": "4.7.1",
    "eslint-config-airbnb": "15.1.0",
    "eslint-config-dhg-phoenix": "0.0.11",
    "eslint-friendly-formatter": "3.0.0",
    "eslint-plugin-import": "2.7.0",
    "eslint-plugin-jsx-a11y": "5.1.1",
    "eslint-plugin-react": "7.3.0",
    "glob": "^6.0.0",
    "gulp": "3.9.1",
    "gulp-autoprefixer": "4.0.0",
    "gulp-cached": "1.1.1",
    "gulp-environments": "0.1.2",
    "gulp-iconfont": "9.0.2",
    "gulp-load-plugins": "1.5.0",
    "gulp-minify-css": "1.2.4",
    "gulp-nodemon": "2.2.1",
    "gulp-notify": "3.0.0",
    "gulp-plumber": "1.1.0",
    "gulp-rev": "8.0.0",
    "gulp-rev-replace": "0.4.3",
    "gulp-sass": "3.1.0",
    "gulp-sass-inheritance": "1.1.0",
    "gulp-size": "^2.0.0",
    "gulp-sourcemaps": "2.6.1",
    "husky": "0.14.3",
    "isomorphic-fetch": "2.2.1",
    "longjohn": "0.2.12",
    "mkdirp": "0.5.1",
    "mocha": "3.5.0",
    "node-neat": "^1.7.0",
    "nyc": "12.0.2",
    "proxyquire": "1.3.1",
    "rosie": "2.0.1",
    "shelljs": "0.8.1",
    "sinon": "3.2.1",
    "sinon-chai": "2.13.0",
    "sinon-stub-promise": "4.0.0",
    "vinyl-paths": "^2.1.0",
    "eslint-plugin-codeceptjs": "0.4.0",
    "webdriverio": "5.4.14",
    "xmlhttprequest": "1.8.0",
    "browserstack-local": "1.3.7",
    "codeceptjs": "2.0.7",
    "dateformat": "3.0.3",
    "faker": "4.1.0",
    "import-export": "1.0.1"
  },
  "scripts": {
  }
}
stychu commented 5 years ago

hmm yeah I believe there is much more configuration needed to be able to use pgo like you but I don't have time for digging it right now :( BUt thanks @PeterNgTr

stychu commented 5 years ago

Okay, I've checked once again and it seems that I can provide exact PO's and it works. What misleads my judgment is that whenever I provide PO's which I want then I lose the ability for autocompletion and it highlights my functions from the PO's as unresolved/not recognized.

This is when I provide PO's as they're included in the config

Zrzut ekranu 2019-03-15 o 09 23 18

This is when I import the exact PO. I lose autocompletion and its highlighted.

Zrzut ekranu 2019-03-15 o 09 23 01

Both works but I want second one also give me autocompletion... Any idea @DavertMik maybe?

yogainalift commented 5 years ago

I am having the same issues. Would love to have a way to use autocompletion.

stychu commented 5 years ago

Yeah, I didn't found a solution :(