I have a simple Sinatra app in which I want to create a form so users can change their number. However, I don't even get as far as changing the number because "params" is not working. Everything is working well. I can see the parameters in the URL but if I print "params" there is nothing but "Echo".
class MyApp < Sinatra::Application
register Sinatra::ActiveRecordExtension
get '/changenumber' do
p params
p params[:mynumber]
p "Echo"
end
end
And a Form:
<form action="/changenumber" method="GET">
Phone: <input type="text" name="mynumber" value="<%= user.number %>">
<input type="submit" value="Change Number">
</form>
As vu-minh-tan pointed out you should probably use Post instead of Get.
I rebuild your example and It works well:
{"mynumber"=>"test"}
"test"
"echo"
IP - - [TIME] "GET /changenumber?mynumber=test HTTP/1.1" 200 4 0.0005
Based on this, I think your problem is that you just lock at the output in your browser. And thats only the last line in your code. You should probably try something like this:
get '/changenumber' do
"Params: #{params} mynumber: #{params[:mynumber]}"
end
Related
I have a simple form on the page that should take datetime values to the second.
<form>
<label for="eventNotificationTime">Event time (date and time):</label>
<input type="datetime-local" id="eventNotificationTime" name="eventNotificationTime">
<input type="submit">
</form>
When I try to test it I get an error
CypressError
Typing into a datetime input with cy.type() requires a valid datetime with the format YYYY-MM-DDThh:mm, for example 2017-06-01T08:30. You passed: 2022-08-03T09:09:09
How do I enter a time containing seconds?
Test:
cy.get('#eventNotificationTime').clear().type('2022-08-03T09:09:09')
This is a known issue Type into datetime-local input: seconds not accepted #22884
The issue has been resolved in the latest release v10.4.0 (Aug 2 2022).
If you upgrade to this version, you should be able to pass the test.
You need to add step="1" to achieve it:
<input type="datetime-local" step="1" id="eventNotificationTime" name="eventNotificationTime" />
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')
})
My HTML code, here am passing xslx file for parsing,
<form method="post" action="/home/parse_xlsx" enctype="multipart/form-data">
Upload XSLX File <input type="file" name="xlsx_file" id="xlsx_file" />
<input type="submit" value="Post"/>
</form>
My Controller code,
def parse_xlsx
xlsxFile = params[:xlsx_file]
prefix_tmp_path = xlsxFile.path
filename = xlsxFile.original_filename
fullname = File.join(prefix_tmp_path,filename)
require 'roo'
s = Roo::Excelx.new(fullname)
for i in 1..14
puts s.cell(i,3)
end
end
Giving me error ,
file /tmp/RackMultipart20130910-10043-u4nqsc/CMS.xlsx does not exist
When I run the following code on console am keeping my 'CMS.xlsx' file in rails root folder & it is running without any errors.
require 'roo'
s = Roo::Excelx.new("CMS.xlsx")
for i in 1..14
puts s.cell(i,3)
end
Please explain where I am going wrong.
xlsxFile.path is the file's location, you shouldn't have to join in the filename. If you need to save the file, you can rename it the original filename when you move it to it's file location
try
s = Roo::Excelx.new(xlsxFile.path)
I use ng-pattern for validation, use ng-show to display the error message. This works fine on browser, but how do I code it in e2e to test if the error message shows up?
Here is my HTML:
<input type="text" ng-model="test.pname" name="pname" ng-maxlength="30" ng-pattern="/^[a-zA-Z0-9 ]*$/"/>
<span class="custom-error" id="pnameValidate" ng-show="addProviderForm.pname.$error.pattern">
PName can be Alpha-Numeric up to 30 characters – spaces allowed, but no special characters</span>
Here is my e2e script:
input('test.pname').enter('cakes`');
expect(element('#pnameValidate:visible').text()).toMatch(/up to 30 characters/);
input('test.pname').enter('cakes are good');
expect(element('#pnameValidate:visible').text()).toBe('');
Here is the result from test runner:
expected "" but was "\n PName can be Alpha-Numeric up to 30 characters – spaces allowed, but no special characters"
it seems in the test runner the #pnameValidate always shows no matter what I specify in e2e.
Have you tried adding wait time to the test to allow the UI to catch up with the script?
input('test.pname').enter('cakes`');
expect(element('#pnameValidate:visible').count()).toBe(1);
expect(element('#pnameValidate:visible').text()).toMatch(/up to 30 characters/);
input('test.pname').enter('cakes are good');
setTimeout(function() {
expect(element('#pnameValidate:visible').count()).toBe(0);
expect(element('#pnameValidate:visible').text()).toBe('');
}, 500);
Your problem is ".enter"
change it to ".sendKeys"
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.