Codeception seeInDatabase() not working as expected - codeception

I have problems getting codeceptions seeInDatabase() to work. This is my Cest:
public function testContactMailCheckbox(AcceptanceTester $I) {
$I->scrollTo("#adminMailSettingsForm", 0, -200);
$I->seeInDatabase("pib_users", [
"user_email" => "admin-cest#example.org",
"user_receive_contact_notification" => 0
]);
$I->click("//label[#for='contactMailNotification']", "#adminMailSettingsForm");
$I->waitForJS("return $.active == 0;",10);
$I->wait(100);
$I->seeInDatabase("pib_users", [
"user_email" => "admin-cest#example.org",
"user_receive_contact_notification" => 1
]);
}
The first seeInDatabase() passes, everything is fine. I can verify that this seeInDatabase-Assertion works correctly, by changing the default-data in my database dump. When I change the default data to "user_receive_contact_notification" => 1, the first seeInDatabase fails, which means it is working correctly.
I use $I->wait(100) to verify, that there are no synchronisation-issues. During this timespan I can check via phpMyAdmin, that the row was indeed updated correctly. That means the test should pass.
Here is my Db-config:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://pib.local/'
window_size: false # disabled in ChromeDriver
port: 5555
browser: chrome
capabilities:
chromeOptions:
args: ["--headless", "--no-sandbox", "--disable-gpu", "--window-size=1920,1080"]
- \Helper\Acceptance
- Sequence
- \Helper\DbHelper
config:
\Helper\DbHelper:
user: "root"
password: ""
dsn: "mysql:host=localhost;dbname=pib"
cleanup: true
dump: 'tests/database_dump_tests.sql'
populate: true
reconnect: true
step_decorators: ~
My DbHelper contains only a single function:
class DbHelper extends \Codeception\Module\Db
{
public function putInDatabase($table, $data, $insertOnlyIfNotExisting = true) {
// if ignoreDuplicateError is true, only execute insert when not existing already
if($this->countInDatabase($table, $data) == 0 | !$insertOnlyIfNotExisting) {
$this->_insertInDatabase($table, $data);
}
}
}
This might be related to this question. I don't use Laravel though, so just using the seeRecord()-helper isn't going to help me.

Related

Testcafe runs on average 2-3 times slower when using SSL

After installing and using a self-signed SSL certificate by following the official guide here and running our test suites it was discovered that the tests take about 3 times as long. I would expect there to maybe be some sort of delay but that's a lot.
Any ideas on why this is the case?
With SSL: 45 passed (6m 56s)
Without SSL: 45 passed (2m 55s)
.testcaferc.js File
let filtered_tests = [
// Located in editor_page_tests.js
'user_is_able_to_add_a_section_column_row_and_element_to_editor',
'pop_up_element_displays_during_page_preview',
'clicking_button_shows_hides_elements',
'user_is_able_to_save_when_adding_a_video',
'user_is_able_to_save_when_leaving_video_embed_blank',
// Located in courses_page_tests.js
'user_can_preview_existing_course',
'optin_user_can_navigate_through_course',
'manually_added_user_can_navigate_through_course',
// Located in funnels_page_tests.js
'user_can_navigate_through_funnel',
// Located in developer_portal_page_tests.js
'user_can_navigate_to_developer_portal_page',
// Located in members_page_tests.js
'user_can_navigate_to_team_members_page',
// Located in teams_dashboard_pages_tests.js
'user_can_navigate_to_team_dashboard_page',
// Located in workspaces_page_tests.js
'user_can_navigate_to_team_workspaces_page'
]
let isolated_tests = [
// Located in sites_overview_page_tests.js
'user_can_make_site_public',
'user_can_edit_site_name',
'user_can_make_site_password_protected',
'user_can_make_site_private',
'user_can_edit_site_domain',
'changing_site_domain_updates_funnel_urls',
// Located in account_details_page_tests.js
'user_can_edit_account_name',
// Located in account_details_page_tests.js
'user_can_edit_account_password',
// Located in general_page_tests.js
'user_can_edit_workspace_details'
]
let full_filter = filtered_tests.concat(isolated_tests)
let build_filter = () => {
// Purpose: To set the suite that we want to run. (Sanity, Smoke, Regression)
var filter = {}
if(process.env.SCOPE) {
filter = {
testGrep: `^(?!.*(${filtered_tests.join('|')})).*$`,
testMeta: {
scope: process.env.SCOPE
}
}
} else {
filter = {
testGrep: `^(?!.*(${full_filter.join('|')})).*$`
}
}
return filter
}
let determine_concurrency = () => {
// Purpose: To set concurrency dependant on the scope that is passed
let concurrency = 5
if (process.env.SCOPE == 'isolated') {
concurrency = 1
}
return concurrency
}
module.exports = {
assertionTimeout: 5000,
browsers: [
"chrome:headless --window-size=1920,1159 --allow-insecure-localhost"
],
concurrency: determine_concurrency(),
cache: true,
clientScripts: "scripts/hide_notifications.js",
filter: build_filter(),
hostname: "localhost",
pageLoadTimeout: 30000,
quarantineMode: {
successThreshold: 1,
attemptLimit: 3
},
reporter: [
{
name: "spec",
output: "artifacts/reports/spec_results"
},
{
name: "xunit",
output: "artifacts/reports/xunit_results.xml"
}
],
screenshots: {
path: "artifacts/screenshots",
pathPattern: "${TEST}_${DATE}_${TIME}.png",
takeOnFails: true,
thumbnails: false
},
selectorTimeout: 5000,
skipJsErrors: true,
skipUncaughtErrors: true,
src: "tests/**",
ssl: {
pfx: "ssl/testingdomain.pfx",
rejectUnauthorized: true
},
videoEncodingOptions: {
aspect: "16:9",
framerate: 30
},
videoOptions: {
failedOnly: true,
pathPattern: "${TEST}_${DATE}_${TIME}.mp4",
singleFile: false
},
videoPath: "artifacts/recordings"
}

Javascript evaluation failed: input('#login_field','dummy') on running karate feature

I am getting error
"java.lang.AssertionError: failed features:
feature.demo-01: demo-01.feature:16 - javascript evaluation failed: input('#login_field','dummy'), ReferenceError: "input" is not defined in at line number 1"
on running the below feature
Feature: browser automation 1
Background:
* configure driver = { type: 'chrome', showDriverLog: true }
# * configure driverTarget = { docker: 'justinribeiro/chrome-headless', showDriverLog: true }
# * configure driverTarget = { docker: 'ptrthomas/karate-chrome', showDriverLog: true }
* configure driver = { type: 'chromedriver', showDriverLog: true }
# * configure driver = { type: 'geckodriver', showDriverLog: true }
# * configure driver = { type: 'safaridriver', showDriverLog: true }
# * configure driver = { type: 'iedriver', showDriverLog: true, httpConfig: { readTimeout: 120000 } }
Scenario: try to login to github and then do a google search
Given driver 'https://github.com/login'
And input('#login_field','dummy')
And input('//input[#id='password']', 'world')
You must be on an old version of Karate. Use 0.9.5.
Maybe try the ZIP Release first and get familiar: https://github.com/intuit/karate/wiki/ZIP-Release

Why error Connection refused! Is selenium server started?

Trying to run nightwatch after following this: https://github.com/dwyl/learn-nightwatch. This is my config file:
//require('env2')('.env'); // optionally store youre Evironment Variables in .env
const seleniumServer = require("selenium-server");
//const chromedriver = require("chromedriver");
const SCREENSHOT_PATH = "./screenshots/";
// we use a nightwatch.conf.js file so we can include comments and helper functions
module.exports = {
"src_folders": [
"tests/"// Where you are storing your Nightwatch e2e tests
],
"output_folder": "./reports", // reports (test outcome) output by nightwatch
"selenium": {
"start_process": true, // tells nightwatch to start/stop the selenium process
"server_path": seleniumServer.path,
"host": "127.0.0.1",
"port": 4444, // standard selenium port
"cli_args": {
"webdriver.chrome.driver": "./chromedriver.exe"
}
},
"test_settings": {
"default": {
"screenshots": {
"enabled": true, // if you want to keep screenshots
"path": './screenshots' // save screenshots here
},
"globals": {
"waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
},
"desiredCapabilities": { // use Chrome as the default browser for tests
"browserName": "chrome"
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true // turn off to test progressive enhancement
}
}
}
}
function padLeft(count) { // theregister.co.uk/2016/03/23/npm_left_pad_chaos/
return count < 10 ? '0' + count : count.toString();
}
var FILECOUNT = 0; // "global" screenshot file count
/**
* The default is to save screenshots to the root of your project even though
* there is a screenshots path in the config object above! ... so we need a
* function that returns the correct path for storing our screenshots.
* While we're at it, we are adding some meta-data to the filename, specifically
* the Platform/Browser where the test was run and the test (file) name.
*/
function imgpath(browser) {
var a = browser.options.desiredCapabilities;
var meta = [a.platform];
meta.push(a.browserName ? a.browserName : 'any');
meta.push(a.version ? a.version : 'any');
meta.push(a.name); // this is the test filename so always exists.
var metadata = meta.join('~').toLowerCase().replace(/ /g, '');
return SCREENSHOT_PATH + metadata + '_' + padLeft(FILECOUNT++) + '_';
}
module.exports.imgpath = imgpath;
module.exports.SCREENSHOT_PATH = SCREENSHOT_PATH;
When I run nightwatch --config conf.js, I get this error:
Starting selenium server... started - PID: 6296
[Go] Test Suite
===================
Running: Guinea Pig Assert Title
Error retrieving a new session from the selenium server
Connection refused! Is selenium server started?
{ value:
{ message: 'Unable to create new service: ChromeDriverService\nBuild info: version: \'3.8.1\', revision: \'6e95a6684b\', time: \'2017-12-01T19:05:32.194Z\'\nSystem info: host: \'S0026COW1983\', ip: \'10.39.13.81\', os.name: \'Windows Server 2008 R2\', os.arch: \'x86\', os.version: \'6.1\', java.version: \'1.8.0_131\'\nDriver info: driver.version: unknown',
error: 'session not created' },
status: 33 }
This line "webdriver.chrome.driver": "chromedriver_Win32.zip" is pointing to the zip file, you need to unzip the content and point to the exe file instead.

I think Karma is running tests twice

I am trying to test my react app using karma(on PhantomJS2), jasmine, and enzyme. I have noticed that some of my tests are failing. It seems to be because each it block is being called twice(I have confirmed this by putting prints in all my it blocks and they all print twice). I have looked up solutions, but none seem to work. I will include as much details as possible.
Here is my karma.config file:
files: [
{ pattern: 'test/**/*.tsx' }
],
I have also tried these but this had the same result as above:
files: [
{ pattern: 'test/**/*.tsx', watched: false, served: true, included: true }
],
I also tried this, but this caused karma to break:
files: [
{ pattern: 'test/**/*.tsx', included: false }
],
Here an example of one of my it blocks that runs twice(Although this passes if ran, the length being off is causing other tests to fail which I commented out):
it('renders the items', () => {
const wrapper = mount(<PortfolioList />);
const length = 5;
const items = fillArray(length);
// tslint:disable-next-line:no-console
console.log('LENGTH: ' + items.length); //OUTPUTS(twice): LENGTH: 10
wrapper.setState({results: items});
expect(wrapper.find('tbody').children().length).toBe(length);
});
Here is fillArray, even thought it is being called twice. Shouldn't it return an array of size 5 twice in my example? Why is it 10?:
function fillArray(length: number) {
const ary = new Array(length);
for (let i = 0; i < length; i++) {
ary.push(item);
}
return ary;
}
Here is a pic of what I feel is relevant(This is pasted together):

How to allow protractor test to register custom protocol handler in chrome

When I register a custom protocol handler by executing script with browser.executeScript(navigator.registerProtocolHandler(protocol, url, title)); a little icon appears in the address bar that has to be clicked and I have to choose option "allow" (ignore is by default);
but how to do that with protractor ?
I know that chrome options can be set through chromeOptions object in conf file
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['']
}
}
but which option from this list is suitable for my problem
https://peter.sh/experiments/chromium-command-line-switches/
or maybe there is other solution?
I think I figured it out; try this:
capabilities: {
'browserName' : 'chrome',
'chromeOptions' : {
args: [],
prefs : {
custom_handlers : {
'enabled' : true,
'registered_protocol_handlers' : [
{
'default' : true,
'protocol' : '',
'title' : '',
'url' : ''
}
]
}
}
}
}
Obviously fill in the protocol, url and title as applicable.