TestController extend method testcafe
TestCefeとかで引数を使う
package.jsopn
では
"e2e": "testcafe chrome ./test/*-test.js",
コマンド
yarn comman --hoge bar
ソースはこう
import _ from 'lodash';
/** * ["chrome:headless","./test/hoge-test.js","./test/hoge-test.js","--hoge","bar","--fuga","hogehoge"] * を {'hoge': 'bar', 'fuga': 'hogehoge'} に変換 * それからキーをもとに取得 * * @param {*} regex */ const getParam = key => { const args = process.argv.slice(2); const MY_ENV = _.reduce(args, (result, item, key) => { if(item.includes('--')) { result[item.replace('--', '')] = args[key + 1]; } return result; }, {}); if (_.isNil(MY_ENV)) { return null; } return MY_ENV[key]; }
TestCafe await async メソッド
TestCafe await async メソッド
test('テスト名', async t => { const buttonName = await Selector('div').withText(/.*正規表現.*/).withAttribute('class', 'class-name');
こういうのは
こういうメソッド作って
const myMethod = async (regex) => { const buttonName = await Selector('div').withText(regex).withAttribute('class', 'class-name'); return buttonName; };
こう呼ぶ
const buttonName = await myMethod(/.*正規表現.*/);