Assert element color in Selenium IDE
IMHO the idea be the following:we simply need to get css property(color, in particulat) of element before click. and get css property(color ) of the element after click on it.
so it be like (I work on java and we will execute a piece of javascript using jsExecutor to implement getColor function. It will take css selector of the element. And get return its color):
public String jsGetColor(String css){ JavascriptExecutor js = (JavascriptExecutor) driver; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("var x=$(\'"+css+"\');"); stringBuilder.append("return x.css('color')"); //stringBuilder.append("return x.css('background-color')"); String res= (String) js.executeScript(stringBuilder.toString()); return res; }String cssSelectorLink="a[class='mg-friend-12345 friend selected']";WebElement linkToClick = driver.findElemebt(By.cssSelector(cssSelectorLink));String colorBeforeClick = jsGetColor(cssSelectorLink);linkToClick.click();String colorAfterClick = jsGetColor(cssSelectorLink);Assert.assertFalse(colorBeforeClick.equals(colorAfterClick));
Hope it be helpful for you.
well I work in intelij IDEA. So setUp to write selenium tests e.g. be the following:
1) install maven
- Unzip the distribution archive, i.e. apache-maven-3.0.4-bin.zip tothe directory you wish to install Maven 3.0.4. These instructionsassume you chose C:\Program Files\Apache Software Foundation. Thesubdirectory apache-maven-3.0.4 will be created from the archive.
- Add the M2_HOME environment variable by opening up the systemproperties (WinKey + Pause), selecting the "Advanced" tab, and the"Environment Variables" button, then adding the M2_HOME variablein the user variables with the value C:\Program Files\ApacheSoftware Foundation\apache-maven-3.0.4. Be sure to omit anyquotation marks around the path even if it contains spaces.
- In the same dialog, add the M2 environment variable in the uservariables with the value %M2_HOME%\bin.
2) install jdk3)
4) verify that all environment variables you've set properly5) run intelij IDEAselect Project structure to set up installed JDK6)press New.select jsdk. write path where we installed java, e.g C:\Program Files\Java\jdk1.6.0_297)create new project from scratch8) maven module9) 10) 11) add to POM appropriate dependencies:
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.24.1</version> </dependency>
12) if still someting underline with red line , press alt+enter on it >> idea should automatically suggest autoimport.
13)test structure in the project
14)common structure of selenium test
import com.thoughtworks.selenium.SeleneseTestBase;import org.junit.After;import org.junit.Before;import org.junit.BeforeClass;import org.junit.Test;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.firefox.FirefoxDriver;import java.util.concurrent.TimeUnit;public class HomePageTest extends SeleneseTestBase{ static WebDriver driver; @Before public void openFirefox(){ driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); } @Test public void testHomePage(){ driver.get("https://www.google.by/"); WebElement search = driver.findElement(By.xpath("//*[@id=\"gbqfq\"]")); search.sendKeys("laptop"); search.submit(); } @After public void closeFirefox(){ // driver.quit(); }}
15) also don't forget that you can export your created test in selenium IDE as JUNIT4- selenium and open them in IDEA
Regards