How to select specific data in dynamic table using protractor? - protractor

I am trying to automate some scenarios using protractor where we need to verify whether the data is updating in dynamic table.
Please find below
HTML Code:
enter image description here
Table in page:
enter image description here

It can be done by verifying that element is present in the DOM with the added Group ID or Group Name.
For Group ID:
element(by.xpath("*//table//tbody//tr//td[1]//p[text()='Amanda Test
Group']")).isDisplayed()
For Group name:
element(by.xpath("*//table//tbody//tr//td[2]//p[text()='Amanda
Group']")).isDisplayed()

I'm assuming you're using Angular2+, yes?
In your HTML Template, you are probably using an *ngFor directive to populate the table dynamically. Add an index to the *ngFor (it's best practices for updating the DOM) in order to add a dynamic id to each element:
<tr *ngFor="let user of user; index as u" id="user-{{u + 1}}">
<td id="userName-{{u + 1}}">
{{user.firstName}} {{user.userName}}<br />
{{user.userName}}
</td>
<td id="userRoles-{{ u + 1 }}">
<span id="role-{{u + 1}}-{{ r + 1 }}" *ngFor="let role of user.roles; index as r">
{{ role.toUpperCase() + ', '}}
</span>
</td>
<!- Omitted code -->
</tr>
In your Page Object:
// Get first user on the table
get firstUser() {
return element(by.id('user-1');
}
// Get a specific user by id
public getUser(index: number) {
return element(by.id(`user-${index}`);
}
// Get all of the attributes for a single user by id
get userAttributes(index: number) {
return element.all(by.id(`user-${index}`);
}
I am not a fan of xpath selectors. Yes, they are faster. But in code that is dynamic or changes frequently, they are the most fragile of selectors. There is no reason your dynamic data cannot have a dynamic ID that clearly identifies each portion of the code you need.
Good luck!

Related

JAX-RS, #FormParam display result in the same page

I have this program that I am coding, the main thing is mostly to get familiar with Jax-rs and rest API. I am sending from a form in JSP page one input and with POST I pass it to my java Response class(that I use annotation #FormParam), it does what calculation I need and then I get the result in another link, what can i do to take the result just below my button on the same page? For my button function I use javascript, and when I push it I don't want to be redirected and take the result like this.
So i use this form and a javascript function in my jsp to pass the value in my POST method in java throw #FormParam
<form name="Form1" method="post">
<p>
Name : <input type="text" name="malename" id="malename" autofocus
value="enter your name..." />
</p>
<input type="submit" name="action" id="malename" value="I'm feeling lucky"
onclick="OnButton1();"> </form>
function OnButton1() {
document.Form1.action = "webapi/perfectmatcher/mate"
document.Form1.target = "_self"; // Open in a new window
document.Form1.submit(); // Submit the page
//return;
}
Here after i have the value i use two other classes to do the calculations and return the result i need. In a few words i pass a value in my form and when i push the button i am redirected in another link(the path of POST) and i display the result. I want to display the result below my button. I hope the code is helpful and i hope i am clear with my explanation
#POST
#Path("/mate")
#Produces(MediaType.TEXT_PLAIN)
public Response postMaleName(#FormParam("malename") String malename) {
String femalename = NumMatcher.numMatcher(Numberizer.numberizer(malename));
// FemaleName female = new FemaleName(femalename);
female.setName(femalename);
System.out.println(female.getName());
return Response.status(200).entity("Perfect Match for " + malename + " is " + femalename).build();
}
P.S.:The object female that i am trying to create its for testing purposes, i was trying somehow to get the information that i store but i cannot find how!!I used even jsp expressions but i get null value of course ...
<%
FemaleName female = new FemaleName("john");
String string = female.getName();
out.print(string);
%>

Angularfire: How to Filter with a Specific key or ID

So here is my quick code.
var thisisformykeyorid =$scope.id;
var ref = firebase.database().ref('/myusers/').child("users");
$scope.users= $firebaseArray(ref);
var query = ref.orderByChild("timestamp").limitToLast(100);
$scope.filteruser= $firebaseArray(query);
In my HTML is
<div ng-repeat="samplein filteruser>
<h2>{{ sample.firstname}}</h2>
<p>{{ sample.age}}</p>
</div>
So in firebase there are unique id or keys for each set of data.
How do i add a filter or query to select a set of data from firebase using my variable ? (assuming $scope.id is a unique key) Please be guided that i dont want to use ng-repeat anymore because i only want to view only 1 set of data. Need help
If you know what object you want to display, you can use $firebaseObject instead of $firebaseArray:
var ref = firebase.database().ref('/myusers/').child("users");
$scope.user = $firebaseObject(ref.child($scope.id));
And then display it in your HTML with:
<div >
<h2>{{user.firstname}}</h2>
<p>{{user.age}}</p>
</div>

Mootools: get text from clicked link's sibling table node

here's the situation:
| ID | Name | ...
+----+--------+---
| 12 | Henry | ... a whole list of names, ids,&c ...you get the idea
+----+--------+---
| 13 | Julia | ...
+-------------+---
...
all the names are links. when selected, they load the rest of the table for editing by passing the name into a quick mysql query. but since i'm getting dupes, i need to grab the id as well to pass along. i also need it for updating the corrected (and correct!) record.
so, using MooTools, how do i grab the text from the neighbouring sibling when i click the link? hell, even just plain ol' JS will do.
here's the existing function:
function loadRecord(aName) {
console.log("loadRecord called with: "+aName);
user = $('submitterName').value;
id = $('table-id').text; // THIS IS THE PROBLEM RIGHT HERE. >_<
console.log('with user: '+user);
$('recordName').value = aName;
$('addRecordButton').value = 'Update Record';
$('addRecordData').action='_php/updateRecord.php'; // this isn't working either...
var action=$('addRecordData').action;
console.log(action);
checkUserDB(aName,user,id);
}
since there are multiple rows to the table, i can't assign a unique identifier to each ID to any benefit. i'm still stuck trying to pull the table-id's text that relates to the clicked link.
i hope i am clear. any help or illumination would be much appreciated.
TIA crew!
WR!
Here is the solution
HTML
<!--Change your HTML-->
<table>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<tr>
<td>12</td>
<td><a>Henry</a></td>
</tr>
<tr>
<td>13</td>
<td><a>Julia</a></td>
</tr>
</table>
MooTools
window.addEvent('load', function(){
window.addEvent('click:relay(a)', function(event){//Add your selector inside relay
event.preventDefault();
console.log($(this).getParent('td').getPrevious().get('html'));
//Add Your AJAX code here
});
});
Here you are attaching a click event to anchor then selecting
parent(http://mootools.net/core/docs/1.5.2/Element/Element#Element:getParent)
then as you have ID in previous
element(http://mootools.net/core/docs/1.5.2/Element/Element#Element:getPrevious)
you can grab the previous element and get it's HTML
You can check the pen here http://codepen.io/arifmahmudrana/pen/yYQeJX

How to add links in wickets

In java class i need to add list (E.g. list.getFirstName()) to the Label in wicket and that first name shoulb be a hyper link in the html. Below i have code of java and html
the html code
<tr >
<a wicket:id="gotoClass">
<span wicket:id="firstname"></span>
</a>
</tr>
the java class
Iterator<String> brds = list.iterator();
RepeatingView repeating = new RepeatingView("repeating");
add(repeating);
while (brds.hasNext())
{
AbstractItem item = new AbstractItem(repeating.newChildId());
repeating.add(item);
String contact = brds.next();
item.add(new Label("firstname", contact));
}
The above code works for me and i am able to add the label i.e if i have 10 first names in the list i am able to add 10 labels in html.But i try to add the anchor tag in html and
form.add(new BookmarkablePageLink<String>("firstname", gotoClass.class)); in java
then i get the below exception
Last cause: Unable to find component with id 'firstname' in [ [Component id = formname]]
Expected: 'formname.firstname'.
Found with similar names: ''
can anybody help me on this
Regards
Sharath
The link element must be son of the repeating element (as you did firstly). For example:
//...
BookmarkablePageLink<String> link = new BookmarkablePageLink<String>("firstname", gotoClass.class);
item.add(link);
link.add(new Label("firstname", contact));

PHP Undefined Index Notice / Error

A page I have in my app will not display the required text so I checked my Apache error log and I found the following notice/error.
PHP Notice: Undefined index: PetManager_Model_Groomprocedures display.phtml on line 34
It is due to the fact that I'm trying to display a result from a query and it can't seem to obtain this item from my result array.
The situation is I'm querying a booking table that is related to a services table (theses elements display fine) the services table is in turn related to a procedures table(this is the element that will not display).
Can someone tell me where I'm going wrong i.e. my Query or my display code and how can I get this to work.
Query Code from my Display Action
if ($input->isValid()) {
$q = Doctrine_Query::create()
->from('PetManager_Model_Kennelbooking k')
->leftJoin('k.PetManager_Model_Kennelservices s')
->leftJoin('s.PetManager_Model_Groomprocedures g')
->leftJoin('k.PetManager_Model_Clients c')
->leftJoin('k.PetManager_Model_Kennels l')
->where('k.kennelbookingID = ?', $input->id);
if('k.groomingIncluded'==1)
{$q->addWhere('s.groomingGiven=g.groomProceduresID');
}
$result = $q->fetchArray();
if (count($result) == 1) {
$this -> view -> booking = $result[0];
The display code from my phtml file
<td class="key">Grooming Procedure </td>
</tr>
<tr>
<?php if($this->booking['PetManager_Model_Kennelservices']['groomingGiven']==NULL)
echo '<td>'.'There is no grooming procedure associated for this booking'.'</td>';
else echo '<td>'.$this->escape($this->booking['PetManager_Model_Groomprocedures']['groomprocedure']).'</td>';
;?>
</tr>
Many thanks in advance,
Graham
As you can see the index PetManager_Model_Groomprocedures is not defined in the booking-variable.
To see which keys are available do the following in your controller to get a debug output.
echo '<pre>';print_r($result[0]);echo '</pre>';exit;
You will see which keys are available in this array. I guess you are not selecting the wanted row explicitly. You will modify your query this way, that you also do select the wanted row.