How to get value from html response in Gatling - gatling

I am trying to get a value from HTML response using Gatling.
Something like
<span>
<input type="hidden" id="Id" name="userId" value="some value"/>
I want to ge the "value" with
.check(xpath("xpath from browser").find.is("value").saveAs("userId"))
But this does not work. How can I get that?

I haven't used xpath checks much, but you can probably achieve the desired result with the css check
.check(css("#Id","value").saveAs("userId"))

According to gatling documentation
XPath only works on well-formed XML documents, which HTML is not.
If you’re looking for path based engine for parsing HTML documents, please have a look at our CSS selectors support.
Another option may be regex.

Related

Gatling save html intput

I am getting an html response in gatling, containing an input with value.
I need to take that input value, store it and use it in the next request.
Can anyone help me to accomplish that, please?
Example of input:
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/tokenId4578swrtt" />
You can capture values from html responses by using css checks.
So, for your example on the request that returns the html page you would have:
.check(css("#__EVENTVALIDATION","value").saveAs("validationToken"))

Which locator to use for this piece of code which is input field

I have a question, there is another input field which I do not understand how to use locator for. In the code it is
'<input _ngcontent-tvt-19="" class="form-control ng-pristine ng-valid ng-touched" placeholder="You can search keywords" type="text">
I want to fill this field with a value using the code in spec file as
'element(by.binding('You can search keywords ')).sendKeys("04");
But it does not work. I have also tried with cssContainingText and it did not work. Do you have any idea about the locator or how can I change the code line.
You can use by using xpath, as below it will work
element(by.xpath("//input[#placeholder='You can search keywords']"));
Easiest solution would be to add an ID or a class to your input field and then use:
element(by.Id(<id>))
or :
element(by.css(<class_name>))
Here are a couple of examples:
$('input[placeholder="You can search keywords"]')
$('input[_ngcontent-tvt-19]')

validation with dynamic name in ng-repeat

Im currently having an issue where I want to create multiple form inputs with validation. The form elements I want to
create will be up to 100 duplicated fields. To do this I have used ng-repeat as can be seen in this small example below. As you may notice
I have a dynamic model and name for my input. Everything works fine with the one exception of validation.
When I inspect the element in the html the dynamic name has got applied as expected and the first name input is called
test0. As you may know form validation in angular is done using the form name and input name. As my input is dynamically
named it seems to be causing issues as you can see by my error output it doesnt seem to log the error correctly, however,
if I was to hardcode the name as test0 instead of test{{i}} (which in the html inspection is test0) everything would work.
This is an issue as validation on the duplicated inputs is not doable this way and the only way I can think of resolving this
is outputting 100 html input elements manually with the only difference being the name of each input. This is not Ideal and I was
wondering if anyone knows a way around this issue or if it is a known bug with Angular? Quite possibly I could just be doing something stupid.
<ng-form name="testform">
<div ng-repeat="i in [0,1,2]">
ERROR {{testform.test0.$error}}
<label>
TEST<br />
<input name="test{{i}}" ng-model="$parent.test[i]" type="text" required />
</label>
</div>
Any help with this matter would be greatly appreciated as I have spent a considerable amount of time trying to resolve this issue.
Thanks.

angular "query" property : where is it defined?

AngularJS noob here.
I'm going thru the tutorial (https://docs.angularjs.org/tutorial/step_03) and see this in the example index.html template:
Search: <input ng-model="query">
I don't see any mention of a 'query' property in the accompanying JS files (controllers.js, etc).
Is query a property of the $scope object? If so is there a documentation for it? Can't seem to find one.
Thanks!
In this example query is not used in the JavaScript at all, so it isn't mentioned there.
It is created by <input ng-model="query"> and later used by the filter in phone in phones | filter:query.
With this html Angular watches for changes to query from typing into <input> and then reapplies the ng-repeat passing the new query value to filter.

How to find an element using Selenium WebDriver, when Id is not contant (<input id="ext-gen26")

I need help in finding an element using Selenium WebDriver. I have tried all the possible selectors, but I am unable to locate the element.
FYI. id="ext-gen26" is not constant, this will change every time when the new page is loaded.
Tried Selectors:
By.xpath("//button[#class=\"x-btn-text\"]/text()='Find Accounts'")
By.cssSelector(input[name='id'])
By.id("ext-gen26")
Code:
<div id="x-form-el-ext-gen26" class="x-form-element" style="padding-left:155px">
<input id="ext-gen26" class="x-form-text x-form-field " type="text" name="id"
autocomplete="off" size="20" style="width: 212px;">
</div>
I want to locate Account ID element and send text to located element.
Appreciate if you can please shed some lights.
Does the div's id change everytime you load a new page too ?
I suggest to you to write something like that :
css Selector : "div.x-form-element input"
But, if you have a lot of div with x-form-element as class value, you can use the nth-child() function. like :
css Selector : "div.x-form-element:nth-child(n) input" // n is the position order of your div that has x-form-element as class value.
nth-child() documentation
Here is my approach: use ExtJS component query on client side to get the ID, then use the ID to locate WebElement. To send keys, you usually need to dig one level deeper to get the "inputEl". Java Code sample:
//a fully qualified ExtJS component query that will return one match only
String query = "viewport #panel1 textfield[fieldLabel='Test Field']";
//use component query to find id
String js = "return Ext.ComponentQuery.query(\"" + query + "\")[0].inputEl.id;";
String id = (String) ((JavascriptExecutor) _driver).executeScript(js);
WebElement element = driver.findElement(By.id(id));
element.sendKeys("it works");
Your application under test must be having labels behind input fields, combo boxes, check boxes etc.
Please try something like below, considering you application is having label as "Account ID"
(//*[text()='Account ID']/following::input)[1]
HTML code will looks like this-
<html>
<div id="x-form-el-ext-gen26" class="x-form-element" style="padding-left:155px">
<label>Account ID: </label>
<input id="ext-gen26" class="x-form-text x-form-field " type="text" name="id"
autocomplete="off" size="20" style="width: 212px;">
</div>
</html>
This kind of xpath will never fail unless there is change in label.

Resources