assertText in Selenium IDE: always true, due to target being display:none - selenium-ide

My webapp has a display:none div with the text "request ok". When the Ajax request is done, this becomes display:block and so it's shown to the user.
I'm using assertText via Selenium IDE to test this page, but the assert never fails, due to the fact that the div always exists.
Do a assertTextIsShown()-like function exists?
Thanks!

use the following command to test the visibility of the text:
<tr>
<td>assertVisible</td>
<td>locator</td>
<td></td>
</tr>

Related

Can i use ngxErrors or something like it to display a form error?

I use ngxErrors to display errors for a form control and it works great. Is there any way to get similar functionality for a form or a form group? Currently, I display a form error like this:
<div *ngIf="form.hasError('loginFailed')">
Login Failed
</div>
The bummer is, when I detect that there is a form error (e.g. after the login form is submitted) as opposed to control error, I set it like this:
this.form.setErrors({ loginFailed: true });
this.cdr.detectChanges();
Where this.cdr is an instance of ChangeDetectorRef. This is necessary because I'm using OnPush change detection strategy. So basically it's like calling $scope.$apply() from AngularJS all over again.
What I would really like to do is something more like how ngxErrors does it:
<div ngxErrors="myForm">
<div ngxError="loginFailed" [when]="['dirty', 'touched']">
The login has failed
</div>
But ngxErrors expects myForm to be a control.
This feature is not currently baked into ngxErrors, but I submitted a PR. https://github.com/UltimateAngular/ngxerrors/pull/18
The working syntax is a slight modification of the above:
<div ngxErrors>
<div ngxError="loginFailed" [when]="['dirty', 'touched']">
The login has failed
</div>
</div>
I learned that you do not have to tell child components the form, the FormGroupDirective is available to children automatically.
See this library https://www.npmjs.com/package/ng-error-messages for show error messages based on validation rules:
<input placeholder="Texto:" formControlName="text">
<div errorMessage="text" alias="Super Texto" ></div>

Selenium TypeError dead object

I tried to run the following selenium test case (I am using Selenium 2.5.0, Firefox 27), but keep getting the following error:
[error] Unexpected Exception: TypeError: can't access dead object. fileName -> chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js, lineNumber -> 1306, columnNumber -> 8
I searched online, but only people got similar error, I wonder if anyone could give a hint for this problem. I list my test case as follows, and my error comes to the last step, where I try to consume an alert message:
<tr>
<td>selectWindow</td>
<td>name=menu</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>xpath=(//input[#id='I-3'])[33]</td>
<td></td>
</tr>
<tr>
<td>waitForPopUp</td>
<td></td>
<td>30000</td>
</tr>
<tr>
<td>selectWindow</td>
<td>CourseReversalDelete</td>
<td></td>
</tr>
<tr>
<td>selectFrame</td>
<td>name=content</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>name=Delete</td>
<td></td>
</tr>
<tr>
<td>verifyText</td>
<td>id=alertMessageText</td>
<td>Profile Starts successfully Deleted</td>
</tr>
<tr>
<td>click</td>
<td>id=alertMessageButton</td>
<td></td>
</tr>
I've been having the same problem (I am using Selenium 2.5.0, Firefox 27) and it always occur when using multiple "open" commands of a URL. I haven't been able to determine root cause, but have determined a workaround. By breaking into new cases before the error, I can eliminate it.
Far from ideal, but thought it may suffice until we can find a root cause.
my teamate got a solution, and we had a gues about what is happening behind selenium. It looks not firefox fault (https://blog.mozilla.org/addons/2012/09/12/what-does-cant-access-dead-object-mean/), nor could we do anything on firefox (I do not think it is a good idea to change firefox code to avoid the problem as someone recommended). the only thing left for us is to change our project code to avoid it. It worked fine, no such error ocured anymore. we suspect it is due to our code had alert message dialog which is named as "confirm", howvere, this name is used by firefox for its internal alert message, and it needs to be consumed by Selenium. So when Selenium found this message, it immediately consumed it, and later when Selenium test case required to click the alert meesage, it is a dead object. the solution for us is to rename the alert message in our project code as "confirmForm" , then the problem is solved. This si just our guess. I hope this idea is helpful for others.

How to Update asp:Label after AJAX Callback

I'm using the ajaxtoolkit:Rating. It all works fine except I'm trying to write a value to an asp label on the changed event and can't get it to work. Here are the relevant lines of code:
page.aspx
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<td>
<ajaxtoolkit:Rating ID="YourRating" runat="server" BehaviorID="RatingBehavior1" CurrentRating="0"
MaxRating="10" StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar"
ReadOnly="false" FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar"
OnChanged="YourRating_Changed" />
</td>
<td>
(<asp:Label ID="YourRatingNumber" Text="" runat="server"></asp:Label>)
</td>
</LoggedInTemplate>
<AnonymousTemplate>
<td>
Login or Register to Rate
</td>
</AnonymousTemplate>
page.aspx.cs
protected void YourRating_Changed(object sender, AjaxControlToolkit.RatingEventArgs e)
{
((HtmlGenericControl)FindControl("MainContent_LoginView1_YourRatingNumber")).InnerHtml = e.Value;
}
What I'm trying to do is update my asp:label control named "YourRatingNumber" text to e.value. I've tried many ways. I realize the asp:label is rendered as a span tag but I can't seem to access that value either. How can do this?
Thanks ... Bob
AJAX is asynchronous, meaning that a page load does not occur. Changing the value of a label server-side during an AJAX operation causes nothing client side. You would need to signal the client to update the page. You should use javascript to do this. I do not think you can do this using Web Forms. If you use MVC, you can use their AJAX helpers to do this, but it would require rewriting the site.
I would suggest that you write some javascript to cause an AJAX event and have it update the label when it gets a response. I would also suggest reading http://w3schools.com/ajax/default.asp, it explains how to use javascript to create AJAX requests, but you would need to tweak it a little to work with asp.net.
Also note, you should include whether you are using Web Forms or MVC, although they are similar, they have different handling of AJAX.

Reload MVC2 user control with jQuery

I know I've had a ton of questions today, but still trying to get everything under control learning MVC 2 tie right way. Before I get into the question I already tried the solution offered here but I get an 500 internal server error.
So here's what I'm trying to do, I give the user the ability to select from a list of skills (loaded in a ListView user control) or add a new one to the list and select that. The adding new one is completed (using a WCF service & jQuery) but now I'm trying to reload the skills user control.
According to the solution I linked to I added an action to my AccountController
public ActionResult GetSkillControl()
{
return View("~/Views/Shared/SkillsListView.ascx");
}
I have the control inside a span (so it has a container)
<tr>
<td style="vertical-align:top;"><label for="SkillsListView" title="Skills">Skills:</label></td>
<td class="regElements"><span id="SkillListViewContainer"> <% Html.RenderPartial("SkillsListView"); %></span><%= Html.ValidationMessageFor(m => m.Skills, "*")%><br />
<span id="AddSkillError"></span>
Add: <input type="text" id="NewSkill" class="inputbox" style="width:75px;" /> <input type="button" value="Add" id="AddSkill" name="AddSkill" /></td>
<td></td>
</tr>
And in my jQuery ajax call I have
success: function () {
$('#SkillListViewContainer').load('../AccountController/GetSkillControl');
}
It's when it reaches that point that the JavaScript console in Chrome shows it returns a 500 internal server error. What am I missing here?
Based on the standard routes in ASP.NET MVC, try "/Account/GetSkillControl". Anything you use from jQuery's load method must be a valid URL. The route engine is looking or Account and not AccountController. Also by using the leading "/" it will resolving from the root of the site.

Intercept WordPress Admin Dashboard for Alerts

How can I make a plugin send an alert to one's dashboard at the top right below where the WordPress upgrade notice might normally appear?
I imagine I need some kind of add_filter() or add_action() call in the plugins' code.
Insert the following code in either a functions.php of your theme, or in a plugin. It's a sample that you can adapt and take further. In this demo, I wanted to demonstrate where you could post a message saying that the user needs to update a plugin.
<? function addDashboardAlert() { ?>
<style type="text/css">
.alert {
padding-top:4px;
padding-bottom:6px;
padding-left:302px;
background-color:#ebfbff;
border-bottom:1px solid #CCC;
display:none;
}
</style>
<script type="text/javascript">
$j = jQuery;
$j().ready(function(){ //when page has fully loaded
$j('h2:contains("Dashboard")').parent().prev().after('<div id="my-plugin-alert" class="alert">X Plugin 2.0 is available. Upgrade Now!</div>');
setTimeout("$j('#my-plugin-alert').fadeIn('slow');clearTimeout();",1000);
});
</script>
<? } add_action('admin_head','addDashboardAlert'); ?>
First, it intercepts admin_head to insert some Javascript. In the Javascript, since we know that current WordPress's include jQuery, but loads it with the .noConflict() option, then we can assign the jQuery to $j to keep it short in our code. When the page has fully loaded, it looks for an H2 that contains "Dashboard", meaning the Dashboard page. It then traverses up the DOM a little to a nice slot where it can insert the alert and then adds one there. It concludes with a professional fadeIn() call.