I am trying to automate a test case using selenium IDE. I have installed this add-on on firefox. I am trying to login using admin/admin credentials in one of the websites and after that it takes couple of seconds to load the next page fully.
<tr>
<td>type</td>
<td>id=username</td>
<td>admin</td>
</tr>
<tr>
<td>type</td>
<td>id=password</td>
<td>admin</td>
</tr>
<tr>
<td>click</td>
<td>css=button.btn</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>30000</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=span.ncs-tree-nav</td>
<td></td>
</tr>
waitForPageToLoad is not working, ideally it should wait for 30 seconds but as soon as login button gets clicked, test case throws error as it is not able to find next element on the page.
Here is the output from IDE :-
[info] Executing: |open | /login.html | |
[info] Executing: |type | id=username | admin |
[info] Executing: |type | id=password | admin |
[info] Executing: |click | css=button.btn | |
[info] Executing: |waitForPageToLoad | 30000 | |
[info] Executing: |click | css=span.ncs-tree-nav | |
[error] Element css=span.ncs-tree-nav not found
As soon as login is done, it moved for searching expected navigation and error came.
It will be helpful if someone can point out if I missed something.
A pragmatic approach,
If you have some visual condition that gets true just when the page is loaded, you can look for that.
Say that the text "Welcome User" gets displayed in a span with id=content somewhere when the page is loaded, you can replace your waitForPageToLoad with
<tr>
<td>waitForText</td>
<td>id=content</td>
<td>Welcome*</td>
</tr>
Possibly you can even be as blunt as
<tr>
<td>waitForText</td>
<td>//body</td>
<td>*Welcome*</td>
</tr>
though I haven't tested the latter myself.
If your page reloads after clicking, you have to use clickAndWait instead of click:
<tr>
<td>clickAndWait</td>
<td>css=button.btn</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=span.ncs-tree-nav</td>
<td></td>
</tr>
If the page does not reload, upper code won't work. In this case wait for a presence of an element that you are going to use on the next step:
<tr>
<td>click</td>
<td>css=button.btn</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>css=span.ncs-tree-nav</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=span.ncs-tree-nav</td>
<td></td>
</tr>
Related
All of this has worked fine for a year, however now I have to separate my goals on the same page between 2020 and 2021. I have "goal_year" as my column within the "goals_table" database table.
I tried to create 2 separate cells where the code pulls in goals for 2020 and goals for 2021 but it makes the entire page show blank.
I'm trying to do this without creating a separate model and controller file.
DATABASE
id | district | goal_year | goal_af_am_msm | goal_b | goal_c
---------------------------------------------------------------
1 | macon | 2020 | 456 | 87 | 234
2 | cobb | 2020 | 987 | 34 | 762
3 | macon | 2021 | 432 | 67 | 819
4 | fulton | 2021 | 843 | 21 | 236
Here's my code:
MODEL
function _goal()
{
$this->db->where('district', 'macon');
$query = $this->db->get('goals_table');
return $query->row();
}
CONTROLLER
public function index()
{
$data['_goal_data'] = $this->Macon_model->_goal(); // GOALS
$this->template->load('admin', 'default', 'macon', $data);
}
VIEW
<td>
<?php echo $_goal_data->goal_af_am_msm; ?> <!-- ENTERED GOALS -->
</td>
ALTERNATE VIEWS THAT I TRIED
1).
<td>
<?php echo $_goal_data->goal_af_am_msm->where('goal_year','2020'); ?>
<!-- Shows entire page blank -->
</td>
2).
<td>
<?php if($_goal_data->goal_year == '2020') echo $_goal_data->goal_af_am_msm ; ?>
<!-- Shows 2020 GOALS but show blank for 2021 -->
</td>
3).
<td>
<?php echo $_goal_data->goal_year == '2020' ? $_goal_data->goal_af_am_msm : ''; ?>
<!-- Shows 2020 GOALS but show blank for 2021 -->
</td>
So I kept playing around with it and I got it figured out. I ended up having to change my model from
return $query->row();
to
return $query->result();
Then I had to update my view file to
<?php foreach($_goal_data as $macon_data) : ?>
<?php if($macon_data->goal_year == '2020') echo $macon_data->goal_af_am_msm; ?>
<?php endforeach; ?>
I want to show product sizes related to product I already have made a relation b/w tables into database i just only want to know that when i click the specific product the size related to that product will be shown in the table.inside function how to make joining b/w three tables please make the join table using DB class because it will be easy to understand for me thanks.
Does Anyone have an idea ?
please check product sizes image
https://i.stack.imgur.com/Yt6Jk.png
Database
product_sizes table
----------------------------------------------------
id | size_name | Body_length | Body_width |
----------------------------------------------------
1 | M | 2.3 | 3.4
2 | L | .5 | 4.4
3 | s | 2.5 | 3.2
4 | xs | 3.5 | 2.4
products table
----------------------------------------
id | product_name | Description |
----------------------------------------
1 Ultraclub 1 | Ultraclub 300 |
2 Ultraclub 2 | Ultraclub 200 |
3 Ultraclub 3 | Ultraclub 500 |
4 Ultraclub 4 | Ultraclub 600 |
5 Ultraclub 5 | Ultraclub 400 |
available_product_sizes table
----------------------------------------
id | product_id | product_size_id
----------------------------------------
1 | 2 | 1
2 | 3 | 4
3 | 4 | 3
4 | 1 | 2
5 | 2 | 3
Controller
public function single_product($product_slug){
$Sizes=DB::table('product_sizes')->get();
$single_product=DB::table('products')->where('product_slug',$product_slug)->get();
return view('front_end/single_product',compact('single_product','Sizes'));
}
html view
<div class="product-tabs__pane product-tabs__pane--active" id="chart">
<table class="table table-bordered text-center">
<tr style="background-color:#3366cc;color:white">
<td><b>Sizes</b>
</td>
<td><b>Body length</b>
</td>
<td><b>Body width</b>
</td>
<td><b>Sleeve length</b>
</td>
</tr>
#foreach($Sizes as $size)
<tr>
<td><b>{{$size->sizes_name}}</b>
</td>
<td>{{$size->Body_length}}</td>
<td>{{$size->Body_width}}</td>
<td>{{$size->Sleeve_length}}</td>
</tr>
#endforeach
</table>
</div>
I assume you're already has/desfined many-to-many relationship between products and product_sizes tables
//App\Product.php
public function sizes()
{
return $this->belongsToMany('App\ProductSize', 'available_product_sizes', 'product_id', 'product_size_id');
}
//App\ProductSize.php
public function products()
{
return $this->belongsToMany('App\Product', 'available_product_sizes', 'product_size_id', 'product_id');
}
In order to get available product sizes you can use :
$sizes = App\Product::find(1)->sizes()->orderBy('size_name')->get();
Controller fix
public function single_product($product_slug) {
$single_product = Product::with('sizes')->where('product_slug',$product_slug)->first();
return view('front_end/single_product',compact('single_product'));
}
View Fix
//...
#foreach($single_product->sizes as $size)
<tr>
<td>
<b>{{$size->sizes_name}}</b>
</td>
<td>{{$size->Body_length}}</td>
<td>{{$size->Body_width}}</td>
<td>{{$size->Sleeve_length}}</td>
</tr>
#endforeach
//...
Answer to the question without using eloquent
use Illuminate\Support\Facades\DB; //include this
$products = DB::table('products as p')
->join('available_product_sizes as aps','aps.product_id','p.id')
->join('product_sizes ps','ps.id','aps.product_size_id')
->where('product_slug',$product_slug)->get();
But it is highly recommended to use eloquent relationships.
I Have following table
<table>
<tbody>
<tr>
<td>First Row | First Column</td>
<td>First Row | Second Column</td>
</tr>
<tr>
<td>Second Row | First Column</td>
<td>Second Row | Second Column</td>
</tr>
<tr>
<td>Third Row | First Column</td>
<td>Third Row | Second Column</td>
</tr>
<tr>
<td>Forth Row | First Column</td>
<td>Forth Row | Second Column</td>
</tr>
<tr>
<td>Fifth Row | First Column</td>
<td>Fifth Row | Second Column</td>
</tr>
<tr>
<td>Sixth Row | First Column</td>
<td>Sixth Row | Second Column</td>
</tr>
</tbody>
I need to use xpath expresion to receive grouped 3 records:
First Row | Second Column, Second Row | Second Column
Third Row | Second Column, Forth Row | Second Column
Fifth Row | Second Column, Sixth Row | Second Column
How I can achive that using only xpath 1.0?
Here you go, xpath expression:
concat(//tr[1]/td[2], ' , ', //tr[2]/td[2], codepoints-to-string(10), //tr[3]/td[2], ' , ', //tr[4]/td[2], codepoints-to-string(10), //tr[5]/td[2], ' , ', //tr[6]/td[2])
The above will return the following string:
First Row | Second Column , Second Row | Second Column
Third Row | Second Column , Forth Row | Second Column
Fifth Row | Second Column , Sixth Row | Second Column
I've been building a rails4 app and running through testing with cucumber and capybara but have hit a snag. I'm doing standard testing for user creation and user edit.
The user create test ran through without any issue but upon running through the test for editing the user I can't get capybara to actually fill in the new values into the fields. The form is the same for new and edit (I am including the same _form partial to both) and again it works fine on new but not edit.
Cucumber New User test:
When I fill in a User with:
| First Name | Rufus |
| Last Name | Firefly |
| Email | rfirefly#fake.com |
| Role(S) | System Admin |
Cucumber Edit User test:
When I fill in a User with:
| First Name | Otis |
| Last Name | Driftwood |
| Email | otis#fake.com |
Corresponding method:
When /^(?:|I) fill in (?:a|an|the) (.+) with:$/ do |obj, fields|
attrs = {}
fields.rows_hash.each do |name, value|
fill_in(name, with: value) unless name =~ /\((?:R|S)\)$/
choose(value) if name =~ /\(R\)$/
select(value) if name =~ /\(S\)$/
end
end
Rendered html form:
<form accept-charset="UTF-8" action="/members/1" class="edit_user" id="edit_user_1" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" /></div><div class='field'>
<label for="user_first_name">First Name</label>
<input id="user_first_name" name="user[first_name]" type="text" value="Ronald" />
</div>
<div class='field'>
<label for="user_last_name">Last Name</label>
<input id="user_last_name" name="user[last_name]" type="text" value="Kornblow" />
</div>
<div class='field'>
<label for="user_email">Email</label>
<input id="user_email" name="user[email]" type="email" value="kornblow#fake.com" />
</div>
<div class='field'>
<label for="user_password">Password</label>
<input id="user_password" name="user[password]" type="password" />
</div>
... omitted fields (not required) ...
<input name="commit" type="submit" value="Update User" />
</form>
Any help or insight anyone could give me I would greatly appreciate it.
Thanks in advance
In your code you have:
When /^(?:|I) fill in (?:a|an|the) (.+) with:$/ do |obj, fields|
attrs = {}
fields.rows_hash.each do |name, value|
fill_in(name, with: value) unless name =~ /\((?:R|S)\)$/
choose(value) if name =~ /\(R\)$/
select(value) if name =~ /\(S\)$/
end
end
here, the fill_in(name, :value) method normally automatically looks for the ID tag id=name, but here your names don't line up exactly as shown by your rendered HTML form.
<div class='field'>
<label for="user_last_name">Last Name</label>
<input id="user_last_name" name="user[last_name]" type="text" value="Kornblow" />
</div>
Try changing your cucumber test to:
When I fill in a User with:
| user_first_name | Otis |
| user_last_name | Driftwood |
| user_email | otis#fake.com |
Hope this helps
So I did find the issue and I'm not happy about the last hour and a half that I lost due to what I believe was the problem...
I was using a nice little debugging tool for capybara to render the page and show it in the browser and this was not displaying the updated fields like I said above, but when i ran click_button() these values were in fact being saved.
The issue I was really having was that Devise, in all its infinite wisdom, was saving the new email address to unconfirmed_email and keeping the old email until the user gets the email and confirms. Makes sense but it was the first time I apparently ran into this.
So in my test:
Given a "User" was updated with:
| Last Name | Driftwood |
| Email | otis#fake.com |
the email attribute really wasn't 'otis#fake.com' and the test, as it always is (no matter how much I argue with it) was right. This user was not updated in with that email. Changing this to:
Given a "User" was updated with:
| Last Name | Driftwood |
| Email | kornblow#fake.com |
| Unconfirmed Email | otis#fake.com |
Solved the problem. I'm still confused why I was not seeing the fill(ed)_in() values when I rendered the page out tho. Kinda led me barking up the wrong tree.
Oh well...
Thanks for your help and hope this helps others...
I have a multidimensional associative array, which I pass to a smarty template. I use below code in my smarty template to generate the shown two tables in my browser.
The smarty code:
<!--language:smarty-->
{foreach from=$allarr key=header item=table}
<h5>{$header}</h5>
<table>
<tr>
<td>{t}Emp #{/t}</td>
<td>{t}Employee Name{/t}</td>
<td>{t}Amount{/t}</td>
</tr>
{foreach from=$table item=sub}
<tr>
<td>{$sub.emp_num}</td>
<td>{$sub.user_name}</td>
<td>{$sub.amount}</td>
</tr>
{/foreach}
<tr>
<td colspan="2">{t}Variation Total{/t}</td>
<td colspan="1">{t}+++{/t}</td>
</tr>
</table>
{/foreach}
The tables:
Table One
________________________________
Emp # |Employee Name |Amount |
________|_______________|_______|
1000001 | Test User | 775.00|
26 | user1 | 555.00|
________|_______________|_______|
Variation Total | +++ |
________________________|_______|
Table Two
______________________________
Emp # |Employee Name| Amount|
________|_____________|_______|
1000001 | Test User | 110.00|
________|_____________|_______|
Variation Total | +++ |
______________________|_______|
What I want, is to replace the "+++" with the actual sum of the values in each Amount column. Nothing seems to work. Can anyone help? Thanks in advance.
Figured out a way. :)
The complete code is below.
{foreach from=$allarr key=header item=table}
<h5>{$header}</h5>
<table>
<tr>
<td>{t}Emp #{/t}</td>
<td>{t}Employee Name{/t}</td>
<td>{t}Amount{/t}</td>
</tr>
{foreach from=$table item=sub}
<tr>
<td>{$sub.emp_num}</td>
<td>{$sub.user_name}</td>
<td>{$sub.amount}</td>
</tr>
{assign var="sum" value="`$sum+$sub.amount`"}
{/foreach}
<tr>
<td colspan="2">{t}Variation Total{/t}</td>
<td colspan="1">{t}{$sum}{/t}</td>
{assign var="sum" value=0}
</tr>
</table>
{/foreach}