How to Determine if Image is Loaded with WatiN - image

I am using WatiN and I need to determine if an image has been loaded. In my case I get the red X on the page but when I use...
var image = WebBrowser.Current.Image(imageName);
if (!image.Exists)
{
Assert.Fail(string.Format("Could not find '{0}' image on the page", imageName));
}
...the Assert doesn't fail because the name of the image does exist on the page. BUT it is not loaded.
Is there a way to use WatiN to eval with JQuery or something that tells me when I get the red X? I have tried every method and property of WebBrowser.Current.Image to no avail.

If i understand correctly you are trying to find the image by name attribute.
If the name attribute is "image_name_attr" (you can verify this by firebug) use this:
WebBrowser.Current.Image(Find.ByName("image_name_attr")); //constraint
If there is a class name on the image you can use:
WebBrowser.Current.Image(Find.ByClass("image_class_attr"));

The Assert is not failing because WatiN is doing exactly what it should; it is checking if the image html element exists. What you need to be checking for is if whether the file exists on the server.
Take a look at this SO question/answer - I've used this approach in the past and it worked mighty fine. Test to see if an image exists in C#

Related

How to assert that image has been uploaded with Capybara?

Let's say I have a form where user can create a post with an image attached to it. I want to make sure the image attached is displayed on the next page:
visit url
fill_in the_form
click_on 'Create'
assert_selector '.post'
post = Post.first
img = page.find '.post .image'
assert_equal post.file.thumb.url, URI(img[:src]).path
But I'm told asserting against database objects in system tests is to be avoided. What do I do then?
So long as there's no "complex" file renaming happening on the backend, you already know the uploaded filename when populating the form:
fill_in the_form
Therefore, you could assert that the page contains an image with this name (perhaps using an xpath).
If there is trivial file renaming (e.g. replacing spaces with hyphens), then you could either (ideally) just choose a filename that does not change, or reproduce the renaming in your test.

best way to show images stored in the app from a webview in SWIFT

I have a webview and would like to show an image in the webview (html)
My HTML :
hello !img src="myimage.png" alt="myimage" height="42" width="42"!
(I used ! as tagend and tagstart, because I don't know how to add this here without be interpreted as HTML, even I pasted as code)
The myimage.png should be stored in app itself and not be loaded from a websource.
I don't know how to do that in a best practice way. Any help ?
UPDATE
I tried with referenced Article, but still not succeeded:
My Code for this:
let path:NSString = NSBundle.mainBundle().bundlePath;
var baseURL:NSURL=NSURL(fileURLWithPath: path as String)!;
var htmlString:String! = texttemp
myWebView.loadHTMLString(htmlString, baseURL: baseURL)
The same Image I can already load like the following -> works:
var image = UIImage(named: "myimage.png");
Your updated code isn't right. You are creating a path to the bundle, not to the specific file. You need to use the NSBundle method pathForResource:ofType (or one of its variants) to build a path to your file. Then use that to create the URL.
The pathForResource:ofType family of methods return nil if the file can't be found, so you should check that you are getting back a path.
EDIT:
Looking at it more closely, I see that you are using the URL as the base URL for a call to loadHTMLString. This does look like a sound approach. What is your HTML string, and where is the image in your bundle?

How to get the src attribute of the element by its id in visual basic 6

I have a page with the following HTML content:
<img src="image.png" id="image">
and in my VB6 code I have a WebBrowser control which loads up that page, and now I want to fetch the src attribute of the image, and I tried this:
Dim image
image = WebBrowser1.Document.getElementById("image")
dim image_src as String
image_src = image.src
But I get the error Invalid qualifier. I debuged the image variable after the getElementById function call and I get: [object].
So, how can I get the src attribute of the image?
edit:
The thing that worked in the end was:
image = WebBrowser1.Document.getElementById("image").src
but to me, this doesn't make any sense, if this upper code works (just tested it), how come the one I tried first doesn't? I would kindly appreciate someone who can provide the explanation to this.
"You often need access to attributes, properties, and methods on the underlying element that are not directly exposed by HtmlElement, such as the SRC attribute on an IMG element or the Submit method on a FORM. The GetAttribute and SetAttribute methods enable you to retrieve and alter any attribute or property on a specific element, while InvokeMember provides access to any methods not exposed in the managed Document Object Model (DOM). If your application has unmanaged code permission, you can also access unexposed properties and methods with the DomElement attribute." -
http://msdn.microsoft.com/en-us/library/system.windows.forms.htmlelement.aspx
Think that suggests what the root issue is. Honestly not sure how assigning the return value changes the htmlElement object accessors. It seems like that is what is happening though. Have not actually written any VB6 code in years, maybe someone else can actually explain why behaves as it does.
Dim image
that is wrong
image = WebBrowser1.Document.getElementById("image")
that is right
set image = WebBrowser1.Document.getElementById("image")
dim image_src as String
image_src = image.src

mColorPicker error 'Invalid Property value' in IE7

I have recently downloaded mColorPicker.js from here
However, I am running into some issue with this -
When user enters an invalid color value like '#454545xxxx' in the color box, I get a js error - Invalid Property value in IE7 (working fine in Firefox)
error is coming in
jquery-1.4.2.min.js,
line 116 - if(e)f[b]=d
when d = "#454545xxxx"
Also, ColorPicker image is hidden for this textbox.
Any ideas?
The reason this is happening is that the plugin is trying to set the value of the background colour to exactly what the user typed, without doing any validation checking to make sure it is a valid colour. The plugin calls the jQuery .css() method to do this, which is why the error is occurring inside jquery-1.4.2.min.js.
If you are able to modify the plugin code, you can then add checks to make sure the value entered is a valid colour before proceeding.
You might also suggest adding this feature to the plugin author, or, if you get it working successfully, submitting your updated code to them so they can benefit from your work.
I had a quick look, but I don't have the time to properly make the necessary changes to the plugin to ensure it correctly validates the colour is valid in all the right places. Good luck!

image using .ashx

i am using .ashx to retrive image and i place the the image inside the ajax update panel it retrive the image when a new image is added to the form but when we change the image it is not updating the image it dont even call the .ashx file but when i refresh the browser it works properly
Sounds like a caching issue. Try adding some of the lines found here to your ashx file and it should hopefully force the browser to rerequest the image. (I know that the link is for ASP rather than ASP.NET, but things like Response.Expires = -1 should work)
Alternatively, can you change the path to the image in the updatepanel? If you just add a random parameter on to the end of it the browser will treat it as a fresh request (we use the current date/time as a parameter when we're doing this. The parameter is ignored by ASP.NET unless you explicitly reference it)
Do something like this:
var sPath = "../../handlers/ProcessSignature.ashx?type=View&UserID=" + userID + "&d=" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
That puts a 4 character alpha numeric string at the end of your query string. It's not needed, but it will force browsers to pick up the latest version of that image because the URL is different.
I tried the above and some browsers ignore the headers. I threw all of those in and Chrome/FireFox 3 didn't try to update.
IE7 worked sometimes
IE6 just twiddled it's thumbs and asked why it was still in existence.
Changing the path above will fix it in all browsers.

Resources