Verify the background-image?

2,392 views
Skip to first unread message

sridhar ..

unread,
Oct 17, 2012, 6:49:50 AM10/17/12
to webd...@googlegroups.com
Hi All,

I want to verify the background image by using CSS properties.....could you please suggest,the way i am writing is correct or wrong.

Problem:Except background-image i am able to verify the all the properties.Please find the below the code to help me.

WebElement ele=d.findElement(By.id("
content_footer"));
        String Actaul=(String)ele.getCssValue("background-image");
        String expected="url(/assets/schlage_footer_logo.gif)";
        Assert.assertEquals(expected, Actaul);

I am getting error......

Help would be appreciate...

Advance thanks..

Regards,
Siddu

darrell

unread,
Oct 17, 2012, 11:19:12 PM10/17/12
to webd...@googlegroups.com
Not really enough information here. Image you are hired to file defects on an application you are testing. The developers are located in a completely different. If they had to ask a question, you'd answer it, they'd have another question, you'd answer that, etc. and the turn around time is one message a day. At that rate it might take days to solve the problem. This is sort of what posting a request for help here is like. The only difference is that no one is paid to help you.

For me to know the answer means I would be able to automate the task as well. Whatever you need to automate the task is what I need to automate the task (i.e. answer the question).

What is ele? is it the BODY tag? Is it a DIV? What is the error you are getting? Why are you casting the return value to a String? It should already be returning a String. Maybe it is an environment issue and nothing to do with WebDriver or your code.

If I use the following it works:



driver.get("http://www.scuba.com");

    WebElement body = driver.findElement(By.tagName("body"));
    String actual = body.getCssValue("background-image");
    String expected = "url(\"http://www.scuba.com/_homepage2012/images/fall-theme-background.jpg\")";
    assertEquals(expected, actual);

Hopefully this will help you with what you are doing differently. You can compare the site's source to your site's source.

sridhar ..

unread,
Oct 18, 2012, 2:13:12 AM10/18/12
to webd...@googlegroups.com
Hi Darrel,

Thanks for your early response and your suggestion,Sorry for not sending the enough information.

I have execute your code,g8t its working .

But my scenario is some what different, if you check the attachment of screen shot,sure you will help me.

Informatin:
Error:expected does not match the actual 

i have to verify the 2 images in footer page which are 1)left corner  of the bottom "Schlage image" and "@ 2012 schlage text"
                                                                             2)right corner  of the bottom" tooltip image"

Waiting for your reply darrell..........

Thanks,
Siddu.
tooltip.docx

alladi sai

unread,
Oct 18, 2012, 3:18:25 AM10/18/12
to webd...@googlegroups.com
Hi Sridhar,

I have executed same thing for your URL. It's working fine at my end, i am able to get the values for the background-image. I am not able to see any error. Can you please share what kind of error your getting . to debug further more.

Regard's
Sai baba



--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/A-VWKPwFZl4J.

To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.



--
Regard's

Sai..

sridhar ..

unread,
Oct 18, 2012, 6:06:15 AM10/18/12
to webd...@googlegroups.com
Hi Sai baba,

Thanks for early response.

Still i am getting error,do not know why,I am using TestNG frame work,could you please correct me where was getting and also please find the screen short to help me.

ERROR:
sridhar ele = true
sridhar ele background-image= url("https://demo.mynexia.com/assets/schlage_footer_logo.gif")
sridhar ele background-color= transparent
****************
Exception in thread "main" org.junit.ComparisonFailure: expected:<url([/assets/schlage_footer_logo.gif])> but was:<url(["https://demo.mynexia.com/assets/schlage_footer_logo.gif"])>
at org.junit.Assert.assertEquals(Assert.java:125)
at org.junit.Assert.assertEquals(Assert.java:147)
at Nexia5.main(Nexia5.java:28)

Kindly check out my script:

import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Nexia5 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver d=new FirefoxDriver();
WebElement ele=d.findElement(By.cssSelector("#content_footer .left"));
System.out.println("sridhar ele = "+ele.isDisplayed());
System.out.println("sridhar ele background-image= "+ele.getCssValue("background-image"));
System.out.println("sridhar ele background-color= "+ele.getCssValue("background-color"));
System.out.println("****************");
//background-image: url("/assets/schlage_footer_logo.gif");
String Actaul=ele.getCssValue("background-image");

alladi sai

unread,
Oct 18, 2012, 6:41:21 AM10/18/12
to webd...@googlegroups.com
Hi Sridhar,

The error u r getting is comparison error .

From selenium you are getting the background-image url is like this "https://demo.mynexia.com/assets/schlage_footer_logo.gif "
But actual value which u r comparing is something is "url(/assets/schlage_footer_logo.gif)"

Which is wrong. Because of that it's throwing an exception.

Regard's
Sai baba

To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/Gi9SZO8VWLkJ.

To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.



--
Regard's

Sai..

darrell

unread,
Oct 18, 2012, 10:23:00 AM10/18/12
to webd...@googlegroups.com
Hi sridhar,

No need to apologize for not providing enough information the first time. Just wanted to let you know how to get help faster. Also hoping more people will read this before they ask for help as well. The below information is pretty good. I guess you want to ensure the correct GIF for the footer background. Good use of CSS but the site will change. On a good development environment you will test on http://localhost, a shared QA machine, a User Acceptance Test (UAT) machine and staging (never do automated testing on production). This means the background-image will change slightly but it should always contain the same value. For that reason I would use:

    driver.get("https://demo.mynexia.com/login"); 
    WebElement ele = driver.findElement(By.cssSelector("#content_footer .left")); 
    String actual = ele.getCssValue("background-image"); 
    String expected = "/assets/schlage_footer_logo.gif"; 
    assertTrue(actual.contains(expected));

This code assumes the filename must be consistent and that images should be stored in the assets/ directory.

Darrell

sridhar ..

unread,
Oct 19, 2012, 9:52:12 AM10/19/12
to webd...@googlegroups.com

Hi darrell,

Thank you so much for your suggestion,its working.....g8t!!!!

Issue solved...

This is my skype id,could you please add me as friend,if you add me i would really happy.

Regards,
Siddu.
Reply all
Reply to author
Forward
0 new messages