I am testing a simple <input type="text" /> element with Cypress.
When I run the following test:
it("should copy and paste", () => {
cy.get("input")
.type("hello {ctrl+a}{ctrl+c}{movetoend}{ctrl+v}{ctrl+v}")
.should("have.value", "hello hello hello ");
});
I get the following assertion error:
expected '<input>' to have value 'hello hello hello ', but the value was 'hello '
It seems to me that {ctrl+c} is not copying the desired value to the clipboard.
For that you should look at this link: Handling Copy and Paste in Cypress
Related
I have a "problem"
I'm trying to upload a file in my cypress test, however my test runs with sucess but it doesn't upload.
I using the library cypress-file-upload;
my code:
const filePath = 'teste.pdf'
cy.get(':nth-child(1) > .backgroundColor > :nth-child(2) > :nth-child(1) > .col-auto > .input-group.mb-0 > .custom-file > .row > .form-group > .input-group > .input-group-text').attachFile(filePath)
result:
enter image description here
my html/css:
enter image description here
button:
enter image description here
ps: sorry for my bad english
I'm trying many css selector until xpath, but doesn't sucess
I think your target element in this case should be the input one.
Make sure teste.pdf is located at fixtures folder and try something like:
const filePath = 'teste.pdf'
cy.get('.custom-file-input.form-control-sm.file-input').attachFile(filePath)
I have password reset page I'd like to perform some tests on. If my current password won't match with my typed current password area it shows a "Password don't match" alert. Here is my alert:
<p-message *ngIf="error" severity="error" id="alert-danger" class="alert alert-danger" text="{{'password.messages.error' | translate}}" >
<ng-template pTemplate>
<div jhiTranslate="password.messages.error" ></div>
</ng-template>
</p-message>
What I've tried so far:
cy.get('[severity="error"] > .p-inline-message > .p-inline-message-text')
.should("have.text","password.messages.error")
But I get an error in cypress saying "expected password.messages.error but the text was Passwords don't match!. Which is understandable it takes directly whatever text was inside my element. Then I've tried:
cy.get('[severity="error"] > .p-inline-message > .p-inline-message-text')
.invoke('attr','jhiTranslate')
.should('eq','password.messages.error')
this gives me "expected undefined to equal password.messages.error"
What I'm doing wrong and what else should I try here?
Just change the text Cypress is checking,
cy.get('[severity="error"] > .p-inline-message > .p-inline-message-text')
.should("have.text", "Passwords don't match!")
The HTML you show above is the source code, but AngularJS has looked up the variable password.messages.error and output the string contained in that variable.
It then removes jhiTranslate from the element, so you cannot test it at runtime (in the browser).
You can see what the runtime HTML is by right-clicking on an element and inspecting it in the dev-tools.
You can do something like:
cy.get('p-message#alert-danger').within(() => {
cy.get('div').should('have.attr', 'jhiTranslate', 'password.messages.error')
})
Suppose I have a file "test.js":
var args = require('yargs')
.command('command', 'command usage here', {alias: "c"} )
.argv;
Then I run:
>node test command
I got this error:
second argument to option must be an object
If I remove the 3rd parameter of .command:
var args = require('yargs')
.command('command', 'command usage here')
.argv;
Everything is fine.
I must make a dumb mistake. But I just cannot figure it out.
Thanks
Your 3rd argument is not required, that's why it works when you remove it. I'm pretty sure the 3rd argument has to be a function call.
var args = require('yargs')
.command('command',
'command explanation',
function(yargs){
//insert yargs.options here
yargs.options({
c:{
demand: true,//if you require the command
alias: 'c',// you will enter -c to use it
description: 'explain what it does'
}
});
})
.argv;
an example of usage might be:
C:\WorkingDirectory>node app.js command -c run
your code could include console.log(args.c);//prints out run
I'm trying to rename a folder from:
<li class="selected rename" id="labelset-624" folderid="624" foldertype="labelset" permissionlevel="2" labelsetid="624">
<div class="folder-insert-drop ui-droppable"></div>
<div class="clear"></div>
<div class="folder-item droppable hoverable empty ui-droppable">
<div id="mlink-labelset-624" class="folder-menu-link" data-hasfullperm="true" data-subfoldertype="undefined"></div>
<div class="expander"></div>
<div class="folder-name labelset label-set">New Label Set</div>
<div class="target-bar"></div>
<div class="folder-rename">
<input value="New Label Set" id="folder-rename-624" maxlength="100" type="text">
</div>
with watir-webdriver using the following commands:
#b.li(:class, "selected rename").div(:class, "folder-rename").text_field.wait_until_present
#b.li(:class, "selected rename").div(:class, "folder-rename").text_field.set labelsetName
#b.li(:class, "selected rename").div(:class, "folder-rename").text_field.send_keys :return
And it gives me the following error:
Watir::Exception::UnknownObjectException: unable to locate element, using {:class=>"selected rename", :tag_name=>"li"}
When I run my test script (test-unit), I can see the value for labelsetName entered into the text field, but it quickly disappears and reverts to the default value. This causes the send_keys statement to err.
When I enter the same commands into irb, it works perfectly. I tried adding sleeps of up to 15 seconds between steps to no avail. Is there any reason the two would work differently? Any suggestions for fixing this going forward?
Unless you have a compelling reason otherwise, try accessing the <input> tag directly using the id attribute:
b.text_field(:id => "folder-rename-624").set "foo"
b.text_field(:id => "folder-rename-624").send_keys :return
And--if there's an associated submit button--try using that instead of send_keys :return.
EDIT: Unfortunately, I can't reproduce the disappearing text issue. But I'm adding this snippet, which should handle the incrementing id attribute:
tfs = b.text_fields
b.text_field(:id => "#{tfs.last.id}").set "foo"
b.text_field(:id => "#{tfs.last.id}").send_keys :return
Turns out that because I had run the test a number of times, each time creating a new folder, that the folder I was trying to rename got pushed off screen. This is what caused the error.
I am new to YAML, and have tried to do a YAML block but I am getting the following error:
while scanning a block mapping: expected , but found: #< ScalarToken Value="content: | This is a test of a test test test test A very very good test yeah yeah A test of test test" Style="None"> (line 8, column 1)
While it works fine without the |, I want whitespace preservation.
YAML file (Home.yml):
---
section:
title: About this site
content: |
This is a test of a test test test test
A very very good test
A test of test test
section:
title: Source code
content: |
Licens:: BSD
Link:: Here
Foo
...
Ruby code:
home = YAML.load_file('data/Home.yml')
home.inspect
Which YAML parser are you using? Both the Ruby 1.8.7 parser and the parser in 1.9 parse the YAML in your question.
There's still trouble, through. The syntax you've given is for a hash like this:
{
'section' => {
'title' => "About this site",
'content => ...
}
'section' => {
'title' => 'Source code',
'content' => ...
}
}
However, you can't have two hash keys be the same. What happens is that the last one wins. You may be looking for an array of hashes. To do that, use this YAML syntax:
---
-
section:
title: About this site
content: |
This is a test of a test test test test
A very very good test
A test of test test
-
section:
title: Source code
content: |
Licens:: BSD
Link:: Here
Foo