"Import" doesn't work on the spec file on Cypress - import

If someone could help me on this please.
I have created page objects with the following code:
class Login {
username(){
return cy.get('#UserName').type('test1')
}
password(){
return cy.get('#password-field').type('test2')
}
loginbtn(){
return cy.get('.btn').click()
}
}
export default Login
Here I have created class Login and imported on the spec file as:
import Login from '../support/PageObjects/Login'
beforeEach('Login to shipment page',() => {
cy.Login()
})
This was working before but now this is not working and I get the error (on hover) telling "Login is declared but it's value is never read." I have changed nothing. I am facing this issue many times but never got the proper solution for this.

The login is not needed to be imported when you have a custom command like cy.Login().
That is why the error occurs:
'Login' is declared but it's value is never read.
Custom commands are global to all tests and never need importing. The Login page is being added to the tests via cy.Login() and you can remove the import without affecting it.

This has to be something to do with your custom command cy.Login(), I imagine the code for it to be something like below:
// cypress/support/commands.js
const login = new require('../PageObjects/Login.js')
Cypress.Commands.add('Login', () => {
login.username()
login.password()
login.loginbtn()
})
Now that of course needs to be imported into cypress/support/e2e.js, but that is the default - check it anyway.
// cypress/support/e2e.js
import './commands.js'
If you are using the Typescript, options are similar.
By the way, what is the file you are having the error from? I suspect that will give a clue.

You have to create an object of the class Login and using that you can access the different methods. So your code should look like this:
import Login from '../support/PageObjects/Login'
const login = new Login()
beforeEach('Login to shipment page', () => {
login.username()
login.password()
login.loginbtn()
})

Related

How to check whether the user is a new user or not in #assistant/conversation package

In the actions-on-google package I have used the following logic to check whether the user is a new user or not.
conv.user.last.seen
But in the new #assistant/conversation package i have used the same logic but it fails stating that the seen is not found. I tried the following logic which shows the current date and time which makes the logic to pass all time.
conv.user.lastSeenTime
Does anyone tried to show whether the user is a new or not in the new #assistant/conversation package?
I ‘m dealing with a similar issue of how to differentiate between new vs returning users with google console’s action builder. The Main invocation is the part of the conversation I'm using this in. (Brand new to the forum so forgive me if I didn’t grasp your question.) I used the same logic as you did, and it did deploy correctly for me using the cloud function's inline editor for the webhook. So I ‘m not entirely sure what’s going on but here are some resources. The following tutorial and code was helpful/ worked for me (https://youtu.be/nVbwk4UKHWw?t=700 )
const { conversation } = require('#assistant/conversation');
const functions = require('firebase-functions');
const app = conversation({debug:true});
app.handle('greeting', conv => {
let message = 'Welcome to App';
if (conv.user.lastSeenTime) {
message = 'Welcome back to App!';
}
conv.add(message);
});
exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);

How to execute browser method inside protractor custom locator?

I want to execute browser method inside the protractor custom locator like:
import {browser} from 'protractor';
protractor.by.addLocator("demo",(selector: string) => {
browser.executeScript('my script')
});
This throws error like:
protractor_1 not defined.
Any help will be valuable.
Add on: Let me know, if we can use async /await inside custom locator.
The problem is CLEARLY NOT in the code you posted.
Somewhere you're using protractor_1, which is not defined. Look for it in your code
You have imported 'browser' but not the actual 'protractor'
import { browser, protractor } from 'protractor';
browser.executeScript cannot be executed in the context of the browser.
"#param {Function|string} script. A script to be run in the context of the browser.
Follow up the documentation: https://www.protractortest.org/#/api?view=ProtractorBy.prototype.addLocator

cakephp 3.0 'App\Controller\ContactForm' not found modelless form

I am trying to create a modelless form using cakePHP 3.0, I have been following the guide through the cookbook here http://book.cakephp.org/3.0/en/core-libraries/form.html but it seems I am getting confused as to where to put ContactForm.php. It says to put it in src/Form/ContactForm.php but it did not work. Can someone direct me to this? Thanks
Pls, provide a bit more info about your problem
1) is ContactForm recognized in controller?
if not - check namespace
2) handle your data only in
protected function _execute(array $data)
{
// Send an email.
return true;
}
not in controller's
if ($this->request->is('post')) {
if ($contact->execute($this->request->data)) {
//NOT HERE!!!
} else {
// error
}
}
Also bear in mind that your server configuration may forbid php short open tags.
Make sure your class starts with <?php and not only <? to be on the safer side. If not, CakePHP will simply respond by the Your\Namespace\Class Not Found message.
Just verify where you have put Form Folder, it must be inside src Folder.
Also be sure that the class has Form as suffix.
Because your error is App\Controller\ContactForm not found, that means that you have NOT put Form Folder inside src Folder.

Why is ic-ajax not defined within certain functions in Ember CLI?

Forgive my ignorance, but I can't get ic-ajax working inside of certain
functions.
Specifically, I'd like to get a test like this working, but for Ember CLI:
e.g. http://coderberry.herokuapp.com/testing-your-ember-application#30
I can call ajax inside Ember.Object.Extend and outside of functions and object definitions, but not in modules, tests, or Ember.Route's model function.
Am I misunderstanding something or is there a misconfiguration in my app?
I've figured out that within functions I can do:
ajax = require('ic-ajax')['default'];
defineFixture = require('ic-ajax')['defineFixture'];
but I'm pretty sure import at the top of the file is supposed to work.
I'm experiencing this on Ember 0.40.0 (both in my existing app and a fresh app). See below for more specifics where I'm finding it undefined. Setting var ajax = icAjaxRaw outside of the functions does not work either. I'm at a bit of a loose end so any help you could give in this regard would be great.
users-test.js:
import ajax from 'ic-ajax';
import { raw as icAjaxRaw } from 'ic-ajax';
import { defineFixture as icAjaxDefineFixture } from 'ic-ajax';
debugger;
---> icAjaxDefineFixture IS defined here
module('Users', {
setup: function() {
App = startApp();
debugger;
icAjaxDefineFixture --> UNDEFINED
},
teardown: function() {
Ember.run(App, App.destroy);
}
});
test("Sign in", function() {
icAjaxDefineFixture --> UNDEFINED
expect(1);
visit('/users/sign-in').then(function() {
equal(find('form').length, 1, "Sign in page contains a form");
});
});
Brocfile.js (I don't think these are actually needed with the new ember-cli-ic-ajax addon):
app.import('vendor/ic-ajax/dist/named-amd/main.js', {
exports: {
'ic-ajax': [
'default',
'defineFixture',
'lookupFixture',
'raw',
'request',
]
}
});
Had the same problem. Turns out it is a Chrome debugger optimization issue, checkout this blog post http://johnkpaul.com/blog/2013/04/03/javascript-debugger-surprises/
While debugging, if you try to use a variable from a closure scope in the console, that wasn’t actually used in the source, you’ll be surprised by ReferenceErrors. This is because JavaScript debuggers optimize the hell out of your code and will remove variables from the Lexical Environment of a function if they are unused.
To play around in debugger, I've just typed ajax; inside of the closure and variable magically appeared.

Can I do more than one form for the same model class in symfony?

Well, imagine that we have a register form of a class Customer and we only ask three fields (name,surname,email) and after, when this user logged first time we want to complete this information.
First, we have in lib/form/doctrine a file called 'CustomerForm.class.php' wich is generated automatic on command line. In this file we 'setup' only 3 fields and validators and if we wanna use we do something like that:
$this->form = CustomerForm();
Second, we create manual another form named 'CustomerFormStep1.class.php' where we can setup for validate the other fields. But when we do..
$this->form = CustomerFormStep1();
it returns error: Fatal error: Class 'CustomerFormStep1' not found
What is wrong?
Thanks.
Assuming you have the form defined as:
class CustomerFormStep1 extends sfForm
or similar (sfFormDoctrine etc), and named correctly like you say (CustomerFormStep1.class.php) and in lib/form, then Symfony should just pick the definition up fine. Did you clear the cache after creating and placing it in the right place? (symfony cc).
Create the new CustomerFormStep1 class as #richsage instructed. Then, in your actions you can write something like:
public function executeLogin(){
//before login
$this->form = new CustomerForm();
}
public function executeLoggedIn(){
$this->form = new CustomerFormStep1();
//other steps
}
Haven't you read the tutorial? Extending forms is perfectly described in context with reh admin generator and can of course be applied to any case.