How can i get the href value per "a"?
<div class="nea-sidebar" _ngcontent-c2="">
<a class="sidebar-item active" href="#/test" _ngcontent-c2="" routerlinkactive="active" ng-reflect-router-link="test" ng-reflect-router-link-active="active">
<i class="sidebar-icon fas fa-play" _ngcontent-c2="" ng-reflect-klass="sidebar-icon fas" ng-reflect-ng-class="fa-play"></i>
<span class="sidebar-label" _ngcontent-c2="">Start Test</span></a>
<a class="sidebar-item" href="#/sequences" _ngcontent-c2="" routerlinkactive="active" ng-reflect-router-link="sequences" ng-reflect-router-link-active="active">
<i class="sidebar-icon fas fa-project-diagram" _ngcontent-c2="" ng-reflect-klass="sidebar-icon fas" ng-reflect-ng-class="fa-project-diagram"></i>
<span class="sidebar-label" _ngcontent-c2="">Sequences</span></a>
This is only a part of the code, I have 5 different href to get
I'm using:
element.all(by.css('a')).count().then(function(numberOfTRs) {
for (let i = 1; i <= numberOfTRs; i ++) {
expect(element(by.css('a')).getAttribute('href')).toMatch('http://localhost:4200/#/sequence');
}
});
It Returns
returns:
- Expected 'http://localhost:4200/#' to match 'http://localhost:4200/#/sequence'.
- Expected 'http://localhost:4200/#' to match 'http://localhost:4200/#/sequence'.
- Expected 'http://localhost:4200/#' to match 'http://localhost:4200/#/sequence'.
- Expected 'http://localhost:4200/#' to match 'http://localhost:4200/#/sequence'.
- Expected 'http://localhost:4200/#' to match 'http://localhost:4200/#/sequence'.
- Expected 'http://localhost:4200/#' to match 'http://localhost:4200/#/sequence'.
Executed 1 of 1 spec (1 FAILED) in 22 secs.
For only getting all href values of all a elements you can do the following:
element.all(by.tagName('a')).map((function (el) {
return el.getAtrribute('href');
});
Probably you are going to check if a set of links is present on the page. You could achieve that as follows:
// the urls you are expecting to be on the page
var expectedUrls = ['/home', '/sequence', '/other'];
element.all(by.tagName('a')).map((function (el) {
return el.getAttribute('href');
})).then(function (urls) {
urls.forEach(function (url) {
expect(expectedUrls.some(function (expUrl) {
return expUrl === url;
})).toBeTruthy();
});
});
Explanation:
element.all(by.tagName('a')) collects all a elements
.map() converts all elements to its href value.
array.some() checks wheter atleast one element fullfills condition
=> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some
Let me know if you have any questions or provided code doesn't work out. (did not test)
I went about this a slightly different way. I like that I can easily add more validation and expects on each element within the loop; hopefully someone else finds this helpful. Any feedback is appreciated!
// Ideally you'd be using POM
const tempElements = element.all(by.css('a'));
// Check for '/' in url and print list of hrefs to console.
async function getElementsLinks(elements: ElementArrayFinder){
const tempList = [];
for (let i = 0; i < await elements.count(); i++) {
const temp = await elements.get(i).getAttribute('href');
expect(temp).toContain('/');
tempList.push(temp);
}
console.log(tempList);
}
// Call the function on an ElementArrayFinder object
await getElementsLinks(tempElements);
Related
I have a button that needs to pass a filtered collection from a table. Now when I click on the button, I get the entire collection
my button
$this->crud->addButtonFromView('top', 'withdrawDebtCompany', 'withdraw_debt', 'end');
button view
<form action="{{ url($crud->route.'/withdrawAllCompanyDebt') }}" method="POST">
<button class="btn btn-warning" data-style="zoom-in">
<span class="ladda-label">
{{ trans('columns.debt.allwithdraw') }}
</span>
</button>
{{ csrf_field() }}
</form>
method
public function withdrawDebtCompany()
{
$bills = $this->crud->query->get();
Bill::tryWithdrawalsIncrement($bills);
$res['success'] = 0;
$res['err'] = 0;
$bills->each(function($bill) use(&$res){
$paym = new PaymentsController();
$result = $paym->payDebt(new Request([
'bill_id'=>$bill->id,
]));
if($result['code'] == 0) {
$res['success'] += 1;
} else {
$res['err'] += 1;
}
});
\Alert::add('warning', 'Успешно списано: '.$res['success'].' | Неуспешно списано: '. $res['err'])->flash();
return redirect()->back();
}
I tried tracking the filtered collection in the button method, but that doesn't work. This is where the whole collection comes in. Filtered collection only comes after page reload
Hope to find you well.
In your <form> element you don't have any input to be POSTed, so I am wondering, why using a form there and not an <a> or similar.
I would advise you to have a look at the ListOperation https://github.com/Laravel-Backpack/CRUD/blob/main/src/app/Http/Controllers/Operations/ListOperation.php
There you will find the search endpoint that is used by datatables to get it's data.
You can apply a similar solution in your button endpoint to get the filtered results like in table.
Cheers
inside Laravel Blade file I'm trying to achieve a simple password generator button that inputs generated password in field
Button:
<a class="btn btn-xs btn-success" onClick=generatePass()>Generate Me</a>
<script>
function generatePass() {
var hashed_random_password = Hash::make(str_random(12));
$('#password').val(hashed_random_password);
}
</script>
The button works, tested by using console.log('button clicked');
But hashing doesn't work, I need to achieve generating a hashed password and inputs it value directly into the password form field
Any suggestion how to get that simply in blade without invloving the routes and controller files?
<a class="btn btn-xs btn-success" onClick=generatePass()>Generate Me</a>
<script>
function generatePass() {
var pass = '';
var str='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+ 'abcdefghijklmnopqrstuvwxyz0123456789##$';
for (let i = 1; i <= 8; i++) {
var char = Math.floor(Math.random()* str.length + 1);
pass += str.charAt(char)
}
$('#password').val(pass);
}
Now at your laravel controller Hash this password.
You can't use Hash::make in javascript, that is a PHP/Laravel method.
You can use something like this to generate a random hash:
function generatePass() {
// change 12 to the length you want the hash
let randomPasswordHash = (Math.random() + 1).toString(36).substring(12);
$('#password').val(randomPasswordHash);
}
blade:
<button onclick="generateRandomPassword()">Generate Password</button>
<h2 id="password"></h2>
<script>
function generateRandomPassword() {
$.ajax({
url: '/generate-password',
success: function (data) {
$('#password').html(data);
}
});
}
</script>
route/controller:
Route::any('/generate-password', function () {
return Hash::make(Str::random(12));
});
I am very new at Angular and I am trying to make something where if you click a tab, ng-repeat will show everything with a certain property and if you click a different tab, ng-repeat witll show everything with a different property. However I cant get the tab controller to work along with ng-show. Here is my code:
<ul class = "nav nav-pills" ng-controller = "TabController as tabCtrl">
<li ng-class="{'active':tabCtrl.isTab(1)}">
<a ng-click="tabCtrl.setTab(1)" href = "#"> All </a>
</li>
<li ng-class="{'active':tabCtrl.isTab(2)}">
<a ng-click="tabCtrl.setTab(2)" href = "#"> Online </a>
</li>
<li ng-class="{'active':tabCtrl.isTab(3)}">
<a ng-click="tabCtrl.setTab(3)" href="#"> Offline </a>
</li>
</ul>
...
<div class = "user" ng-repeat="streamer in twitch.users" ng-show="tabCtrl.isTab(1)">
//... repeated stuff here
</div>
Here is the js code for TabController:
app.controller('TabController', function(){
this.tab = 1;
this.setTab = function(t){
this.tab = t;
}
this.isTab = function(t){
return (this.tab == t);
}
})
However ng-show shows nothing as isTab() is always false. Can anyone explain to me why?
Use the pattern I referred to in the comments to keep a reference to the controller object. This is how you might do it using the "controller as" syntax in AngularJS:
app.controller('TabController', function(){
var self = this;
this.tab = 1;
this.setTab = function(t){
// inside a function "this" is not the controller
// it is a reference to the function
self.tab = t;
};
this.isTab = function(t){
return (self.tab == t);
};
})
According to rivetsjs docs, we can render content by iterating over a object (array) by,
<ul>
<li rv-each-todo="list.todos">
<input type="checkbox" rv-checked="todo.done">
<span>{ todo.summary }</span>
</li>
<ul>
but is there a way where I can iterate by using a single integer to indicate number of times the iteration to take place?
I mean something like this,
<li rv-each="list.num_of_todos">
...
where num_of_todos is an integer to indicate number of iterations to take place.
There is no "proper" way of doing it. However, you can easily mimic this using a formatter that returns an array as shown below:
var list = {
name: 'to do list',
noOfToDos: 5
};
rivets.formatters.makearray = function(value) {
var result = [];
while (value--) {
result.push(0)
};
return result;
}
rivets.bind($("ul"), { // bind rivets
list: list
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/rivets/0.7.1/rivets.bundled.min.js"></script>
<ul>
<li rv-each-item="list.noOfToDos | makearray">Test</li>
<ul>
I'm wondering whether its possible to get the class value of a li item, the html looks something like this:
<div id="cardsdeck">
<ul id="cards">
<li id="card-0" class="card-image card-shown" .... >
......
I'm trying to get card-show out of the li.
I'm unsure if this is what you're trying to do, but to get and array of the classes that an element has, you can use:
document.querySelector('#card-0').className.split(' ');
However, if you're trying to get elements that have the card-shown class, then you can use:
document.querySelector('.card-shown');
Edit: better suited for your comment below:
casper.then(function() {
var num = 0;
var shown = this.evaluate(function isShown(k) {
return document.querySelector('#cards li.card-shown').id == ('card-'+k);
}, num);
console.log(shown);
})
This will look for an element with the card-shown class and then check to see if the id matches card-k, with k being a number.