Codeception: Call to undefined method FunctionalTester::expectException - codeception

According to the Codeption documentation I should be able to catch an HttpException by running the following:
$I->expectException(HttpException::class, function () {
$I->amOnRoute('that-doesnt/exist');
});
However instead I get en error:
[RuntimeException] Call to undefined method
FunctionalTester::expectException
I am using Codeception 2.4.3

In order to make expectException method available in the tests, Assert module must be enabled in functional.suite.yml file:
modules:
enabled:
- Asserts

In addition to #Naktibalda answer - in latest version of Codeception expectException was deprecated and replaced with expectThrowable:
https://codeception.com/docs/modules/Asserts#expectThrowable

Related

PrestaShop Call to undefined method FrontController::parseCMSContent() after update to 1.7.8.2

I created some custom shortcodes for my PrestaShop by creating a file (override/classes/controller/FrontController.php) with a method like :
public static function parseCMSContent($content)
{
...
}
And in my module and cms smarty templates I changed:
{$cms.content nofilter}
to:
{FrontController::parseCMSContent($cms.content) nofilter}
Everything was working fine with Prestashop 1.7.7.5, but the update to 1.7.8.2 broke the whole thing.
I get a 500 error saying :
PHP Fatal error: Uncaught Error: Call to undefined method FrontController::parseCMSContent() ... .module.pscustomtextpscustomtext. ...
It's still working fine with debug mode enabled though..
I can't find anything about the function being deprecated, any idea on how I could get this working again please?
In case this can help anyone, I fixed this by moving my override into a new smarty plugin.
I created a file vendor/smarty/smarty/libs/plugins/function.get_shortcoded_content.php
I added my shortcodes in:
function smarty_function_get_shortcoded_content($params, &$smarty)
{
...
}
And in my smarty files I called:
{get_shortcoded_content content=$cms.content}
instead of:
{$cms.content nofilter}
It seems to work all fine again.

How to configure Create-react-app less module with customize-cra(2.x)?

I used create-react-app(typescripts) to build a project, and added antd#3.26.13 with customize-cra as the website I was following told me.
I would like use the module.css, and I want to use module.less, like css, but encountered some error messages:
./src/layout/basic.module.less (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-8-1!./node_modules/postcss-loader/src??postcss!./node_modules/less-loader/dist/cjs.js??ref--6-oneOf-8-3!./src/layout/basic.module.less)
ValidationError: Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options has an unknown property 'localIdentName'. These properties are valid:
object { url?, import?, modules?, sourceMap?, importLoaders?, localsConvention?, onlyLocals?, esModule? }
My code follows:
const {
override,
addWebpackAlias,
fixBabelImports,
addLessLoader,
addDecoratorsLegacy
} = require('customize-cra');
module.exports = override(
addWebpackAlias({
"#":require('path').resolve(__dirname,"src")
}),
fixBabelImports('import',{
libraryName:'antd',
libraryDirectory:'es',
style:true
}),
addLessLoader({
javascriptEnabled:true,
modifyVars:{'#primary-color':'#1DA57A'},
}),
addDecoratorsLegacy()
);
The current version of customize-cra isn't compatible with the latest version of create-react-app, to be precise with css-loader. Try to install customize-cra#next to get alpha version. They fixed that issue there.

Protractor - pass parameters from console to conf.js

I have config.js like below:
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
params: {
browser: 'chrome'
},
capabilities: {
'browserName': (params.browser || 'chrome'),
},
...
}
Now I would like to pass 'browser' parameter from console to run it on IE instead of Chrome by default:
protractor e2e/protractor.conf.js --params.browser='internet explorer'
or
protractor e2e/protractor.conf.js -- --params.browser='internet explorer'
I've tried many configuration but everytime I get:
[14:17:00] E/configParser - Error code: 105
[14:17:00] E/configParser - Error message: failed loading configuration file e2e/protractor.conf.js
[14:17:00] E/configParser - ReferenceError: params is not defined
Can anyone help how to do that?
not enough reputation for clarification :)
Are you sure that you call properly this part params.browser ? I mean params.
To my mind params is not defined. You work with object, so try this one: this.params.browser
If you define your config in config.js, why did you call protractor.conf.js ?
Finally, protractor has it's own globals. And there are some entry points where you can use it. For example you can use global protractor object "browser" in onPrepare(). To get access to the params should work something like "browser.params.browser". I am not sure that you can get access to globals within main conf file while it parsing. May be some workaround with process.argv will help you. Or rework your logic structure.
If your problem is to specify the browser name from cmd line, you can do as following:
protractor e2e/protractor.conf.js --browser='internet explorer'
And you can specify following params as same way:
--seleniumAddress=
--specs="['./src/**/*.e2e-spec.ts', '']"
--capabilities=<json string>
--suite=
Besides above reserved params, you can specify any params through --params.xxx format in cmd line and use browser.params.xxx format in script to use the xxx.
But the browser variable can't be used in anywhere in conf.js, it's only inited after the browser opened.
As protractor website said, you can use browser in onPrepare function and any place where is executed after protractor call onPrepare function.

Trying with Nightwatch + Browserstack to set up a simple login test, failing

Using "nightwatch": "^1.0.11" and "browserstack-local": "^1.3.4"
I have tried this many ways, but I cannot get the examples in the documentation to run.
I have a simple login page with a page object
module.exports = {
url: function() {
return this.api.launchUrl + '/login';
},
elements: {
email: {
selector: '#user_login_email'
},
password: {
selector: '#user_login_password'
},
button: {
selector: '#login-btn'
}
}
};
I then want to run a test to login into the site (NOTE: The first screenshot is fine)
module.exports = {
before(client) {
client.maximizeWindow();
},
'Login' : function (client) {
var login = client.page.login();
login.navigate();
client.waitForElementPresent('body', 500)
.saveScreenshot('tests_output/login.png');
login.setValue('#email', 'test#user.email')
.setValue('#password', 'Pa55w0rd')
.click('#button');
client.pause(1000)
.saveScreenshot('tests_output/login-complete.png');
},
after(client) {
client.end();
}
};
I get the following errors when trying to run the test through browserstack (with the local URL)
✖ login.test
– Login (5.196s)
An error occurred while running .setValue() command on <Element [name=#email]>: Error: First argument passed to .elementIdValue() should be a web element ID string. Received object.
at Function.validateElementId (node_modules/nightwatch/lib/api/protocol.js:36:19)
at ProtocolActions.elementIdValue (node_modules/nightwatch/lib/api/protocol.js:951:25)
at transport.locateElement.then.result (node_modules/nightwatch/lib/api-loader/element-command.js:106:54)
at process._tickCallback (internal/process/next_tick.js:68:7)
at process._tickCallback (internal/process/next_tick.js:68:7)
at process._tickCallback (internal/process/next_tick.js:68:7)
An error occurred while running .setValue() command on <Element [name=#password]>: Error: First argument passed to .elementIdValue() should be a web element ID string. Received object.
[...]
An error occurred while running .click() command on <Element [name=#button]>: Error: First argument passed to .elementIdClick() should be a web element ID string. Received object.
[...]
I have gotten successful tests to run; just not using the documented examples.
For example, the below code works fine to close a cookie message
client
.waitForElementPresent('.cookie-message__button', 5, true, function(result) {
client.elementIdClick(result.value[0].ELEMENT);
})
.saveScreenshot('tests_output/cookie-closed.png');
But obviously it's really long winded.
Any help for what I'm doing wrong would be awesome.
Using the following as an example for the Nightwatch config: https://github.com/browserstack/nightwatch-browserstack/blob/master/conf/local.conf.js with the local runner and running tests in parallel in 3 browsers: https://github.com/browserstack/nightwatch-browserstack/blob/master/scripts/local.runner.js
TL;DR: Documentation examples don't work with version 1.0.11; but Nightwatch and Browserstack are configured correctly as can get a suite to run (in Travis and locally), just with very long-winded code, which I hacked together.
I have created sample project for page objects model here. Also, sample login test is added using page_objects_path.
The compatibility for latest nightwatch version is also added. The latest version of nightwatch seems to have changes which are in compliant with w3c. So we need to use 'browserName' as capability instead of 'browser'

requirejs loading file from different path

I've a webpage , where I've included the requirejs via script tag like -
<script data-main="/media/course-book-app/courses.require.main.js" src="/media/common/vendor/requirejs/require.js"></script>
On Safari browser, I'm getting error like -
What is causing this issue?
This issue is very frequent on Safari but on chrome it is less frequent.
Testing URL
From https://requirejs.org/docs/errors.html#scripterror (which is linked right there in the error). Follow the instructions and look at the script that caused the error
This occurs when the script.onerror function is triggered in a
browser. This usually means there is a JavaScript syntax error or
other execution problem running the script. To fix it, examine the
script that generated the error in a script debugger.
This error may not show up in IE, just other browsers, and instead, in
IE you may see the No define call for ... error when you see "Script
error". This is due to IE's quirks in detecting script errors.
Here is the way to use requirejs correctly. This ensures the configuration gets loaded before loading any module -
define('requireconfig', function(){
require.config({
paths: {
"jquery": "/common/vendor/jquery/jquery-1.9.1.min",
"backbone": "/common/vendor/backbone/backbone.min-1.1.2",
"underscore": mediaPath + "/common/vendor/underscore/underscore.min-1.7.0"
},
shim: {
backbone : {
deps: ["jquery","underscore"],
exports: "Backbone"
},
}
});
});
define('main', ['requireconfig'], function () {
'use strict';
});
// loading main module which loads the requirejs configuration
requirejs(['main'],()=>{
requirejs(['jquery'], ($)=>{//jquery loaded});
}, ()=>{//error loading module})