Confirmation Item Color in Selenium IDE

I am trying to set up test automation that will validate the color of an item when clicked. However, I could not find the right way to do this. I am new to selenium, I tried all possible ways to do this, but could not.

HTML:

<a class="mg-friend-12345 friend selected" title="test" data-cid="12345" style=""> 

CSS

 .imweb #mgifting-dialog .mg-friends .friend.selected, .imweb #mgifting-dialog .mg-friends .non-friend.selected { background-color: #9DD4FD; } 
+4
source share
2 answers

IMHO the idea is this: we just need to get the css property (color, in particular) of the element before clicking. and get the css property (color) of the element after clicking on it.

so (I’m working on java and we will execute the javascript part using jsExecutor to implement the getColor function and take the css selector of the element. And 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 this will be helpful for you.

+2
source

Well, I work at intelij IDEA. So setUp write selenium tests, for example. be as follows:

1) install maven

  • Unzip the distribution archive, i.e. apache-maven-3.0.4-bin.zip to the directory you want to install Maven 3.0.4. These instructions. Suppose you select C: \ Program Files \ Apache Software Foundation. a subdirectory apache-maven-3.0.4 will be created from the archive.
  • Add the M2_HOME environment variable by opening the property system (WinKey + Pause), selecting the "Advanced" and "Environment Variables" tabs, then adding the M2_HOME variable in user variables with the value C: \ Program Files \ Apache Software Foundation \ apache-maven-3.0. 4. Be sure to omit the quotation marks around the path, even if they contain spaces.
  • In the same dialog box, add the environment variable M2 in the user variables with the value% M2_HOME% \ bin.

2) install jdk 3) enter image description here

4) make sure that all environment variables that you set correctly enter image description here 5) run intelij IDEA select "Project Structure" to install the installed JDK enter image description here 6) click New.select jsdk. write the path where we installed java, for example C: \ Program Files \ Java \ jdk1.6.0_29 enter image description here 7) create a new project from scratch enter image description here 8) maven module enter image description here nine) enter image description here ten) enter image description here 11) add the appropriate POM dependencies: enter image description here

  <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.24.1</version> </dependency> 

12), if something else is underlined by a red line, press alt + enter on it β†’ The idea should automatically suggest autoimport.

13) testing structure in the project enter image description here

14) the general structure of the test for selenium

 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 do not forget that you can export the created test to Selenium IDE as JUNIT4-selenium and open them in IDEA enter image description here

Hello

+1
source

Source: https://habr.com/ru/post/1440370/


All Articles