Write a Automation code for background images












0















I need to write automation code (selenium) in Java for
verify scenario how many background images are displaying and at what interval, it is getting changed.



URL:- https://www.seniorhousingnet.com/



@Then ("^Background images should display$")



public void BaackgroundImagesHP(){
WebElement body = Driver.Gprops.GetWebDriver().findElement(By.id("ImagePlaceHolder"));
System.out.println("body is "+body);
String actual = body.getCssValue("background-image");
System.out.println("Actual is "+actual);

}


To find background image, I written a small automation code as you see above,



but if we observe background images are keep changing after a few seconds. I need to write a code for how many background images are displaying and at what interval it is keep changing



can anybody help me?










share|improve this question





























    0















    I need to write automation code (selenium) in Java for
    verify scenario how many background images are displaying and at what interval, it is getting changed.



    URL:- https://www.seniorhousingnet.com/



    @Then ("^Background images should display$")



    public void BaackgroundImagesHP(){
    WebElement body = Driver.Gprops.GetWebDriver().findElement(By.id("ImagePlaceHolder"));
    System.out.println("body is "+body);
    String actual = body.getCssValue("background-image");
    System.out.println("Actual is "+actual);

    }


    To find background image, I written a small automation code as you see above,



    but if we observe background images are keep changing after a few seconds. I need to write a code for how many background images are displaying and at what interval it is keep changing



    can anybody help me?










    share|improve this question



























      0












      0








      0








      I need to write automation code (selenium) in Java for
      verify scenario how many background images are displaying and at what interval, it is getting changed.



      URL:- https://www.seniorhousingnet.com/



      @Then ("^Background images should display$")



      public void BaackgroundImagesHP(){
      WebElement body = Driver.Gprops.GetWebDriver().findElement(By.id("ImagePlaceHolder"));
      System.out.println("body is "+body);
      String actual = body.getCssValue("background-image");
      System.out.println("Actual is "+actual);

      }


      To find background image, I written a small automation code as you see above,



      but if we observe background images are keep changing after a few seconds. I need to write a code for how many background images are displaying and at what interval it is keep changing



      can anybody help me?










      share|improve this question
















      I need to write automation code (selenium) in Java for
      verify scenario how many background images are displaying and at what interval, it is getting changed.



      URL:- https://www.seniorhousingnet.com/



      @Then ("^Background images should display$")



      public void BaackgroundImagesHP(){
      WebElement body = Driver.Gprops.GetWebDriver().findElement(By.id("ImagePlaceHolder"));
      System.out.println("body is "+body);
      String actual = body.getCssValue("background-image");
      System.out.println("Actual is "+actual);

      }


      To find background image, I written a small automation code as you see above,



      but if we observe background images are keep changing after a few seconds. I need to write a code for how many background images are displaying and at what interval it is keep changing



      can anybody help me?







      java selenium-webdriver






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 27 '18 at 9:34









      Mehran

      1791311




      1791311










      asked Nov 27 '18 at 7:42









      Adithya PragadaAdithya Pragada

      62




      62
























          2 Answers
          2






          active

          oldest

          votes


















          0














          You can try something similar to this



                  driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
          HashMap<String, String> imageMap = new HashMap<String, String>();
          boolean isPresent = false;
          String actual = "";
          while(!isPresent){

          //System.out.println("body is "+body);
          String current = driver.findElement(By.id("ImagePlaceHolder")).getCssValue("background-image");
          if(!actual.equalsIgnoreCase(current)){
          WebElement body = driver.findElement(By.id("ImagePlaceHolder"));
          actual = current;
          if(imageMap.containsKey(actual))
          isPresent = true;
          else{
          imageMap.put(actual, new Date().toString());
          System.out.println("Image : " + actual + " appeared at : " + new Date().toString());
          }
          current = body.getCssValue("background-image");
          }
          }


          This gives you all details including fade out frequency. If your requirement is to get only Image load time, Then parse the acutal and current strings to compare only URL value






          share|improve this answer
























          • Thanks Bhargav. But one concern , image keeps changing randomly , consider first time we got img-1 and second time we got img-2 but third time we may get img-1 again .In this case our script is getting stopped because "is present" is changing to True and while loop is changing to False.I know its hard .Anyway thanks and i appreciate the way of code you written.

            – Adithya Pragada
            Nov 27 '18 at 14:40





















          0














          Each image has own unique "aria-label", you can use it.



              WebElement image = driver.findElement(By.id("ImagePlaceHolder"));
          String image_name = image.getAttribute("aria-label");


          To measure changing time you can use LocalDateTime and Duration.between(args)



          LocalDateTime timestamp1 = LocalDateTime.now();
          Long duration_in_seconds = Duration.between(timestamp1, timestamp2).toMillis() / 1000;


          Implemented JavaScript changes the image each 3 seconds. Not sure how will selenium handle it, didn't try it.






          share|improve this answer


























          • Thanks for your reply.But as per your code i will get just image name but i need how many images are there.So for that How i can loop if we do not have know number of images and we do not know after how many seconds will the image change.

            – Adithya Pragada
            Nov 27 '18 at 10:40











          • After page is loaded with first img, add the img name to an ArrayList. Then add each new img. Adding img to the array must be conditional to prevent doubling img names in the array. After "some time" just count element in that array. If I find some free time I'll try to create a full test.

            – pburgr
            Nov 27 '18 at 10:44











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53494892%2fwrite-a-automation-code-for-background-images%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You can try something similar to this



                  driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
          HashMap<String, String> imageMap = new HashMap<String, String>();
          boolean isPresent = false;
          String actual = "";
          while(!isPresent){

          //System.out.println("body is "+body);
          String current = driver.findElement(By.id("ImagePlaceHolder")).getCssValue("background-image");
          if(!actual.equalsIgnoreCase(current)){
          WebElement body = driver.findElement(By.id("ImagePlaceHolder"));
          actual = current;
          if(imageMap.containsKey(actual))
          isPresent = true;
          else{
          imageMap.put(actual, new Date().toString());
          System.out.println("Image : " + actual + " appeared at : " + new Date().toString());
          }
          current = body.getCssValue("background-image");
          }
          }


          This gives you all details including fade out frequency. If your requirement is to get only Image load time, Then parse the acutal and current strings to compare only URL value






          share|improve this answer
























          • Thanks Bhargav. But one concern , image keeps changing randomly , consider first time we got img-1 and second time we got img-2 but third time we may get img-1 again .In this case our script is getting stopped because "is present" is changing to True and while loop is changing to False.I know its hard .Anyway thanks and i appreciate the way of code you written.

            – Adithya Pragada
            Nov 27 '18 at 14:40


















          0














          You can try something similar to this



                  driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
          HashMap<String, String> imageMap = new HashMap<String, String>();
          boolean isPresent = false;
          String actual = "";
          while(!isPresent){

          //System.out.println("body is "+body);
          String current = driver.findElement(By.id("ImagePlaceHolder")).getCssValue("background-image");
          if(!actual.equalsIgnoreCase(current)){
          WebElement body = driver.findElement(By.id("ImagePlaceHolder"));
          actual = current;
          if(imageMap.containsKey(actual))
          isPresent = true;
          else{
          imageMap.put(actual, new Date().toString());
          System.out.println("Image : " + actual + " appeared at : " + new Date().toString());
          }
          current = body.getCssValue("background-image");
          }
          }


          This gives you all details including fade out frequency. If your requirement is to get only Image load time, Then parse the acutal and current strings to compare only URL value






          share|improve this answer
























          • Thanks Bhargav. But one concern , image keeps changing randomly , consider first time we got img-1 and second time we got img-2 but third time we may get img-1 again .In this case our script is getting stopped because "is present" is changing to True and while loop is changing to False.I know its hard .Anyway thanks and i appreciate the way of code you written.

            – Adithya Pragada
            Nov 27 '18 at 14:40
















          0












          0








          0







          You can try something similar to this



                  driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
          HashMap<String, String> imageMap = new HashMap<String, String>();
          boolean isPresent = false;
          String actual = "";
          while(!isPresent){

          //System.out.println("body is "+body);
          String current = driver.findElement(By.id("ImagePlaceHolder")).getCssValue("background-image");
          if(!actual.equalsIgnoreCase(current)){
          WebElement body = driver.findElement(By.id("ImagePlaceHolder"));
          actual = current;
          if(imageMap.containsKey(actual))
          isPresent = true;
          else{
          imageMap.put(actual, new Date().toString());
          System.out.println("Image : " + actual + " appeared at : " + new Date().toString());
          }
          current = body.getCssValue("background-image");
          }
          }


          This gives you all details including fade out frequency. If your requirement is to get only Image load time, Then parse the acutal and current strings to compare only URL value






          share|improve this answer













          You can try something similar to this



                  driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
          HashMap<String, String> imageMap = new HashMap<String, String>();
          boolean isPresent = false;
          String actual = "";
          while(!isPresent){

          //System.out.println("body is "+body);
          String current = driver.findElement(By.id("ImagePlaceHolder")).getCssValue("background-image");
          if(!actual.equalsIgnoreCase(current)){
          WebElement body = driver.findElement(By.id("ImagePlaceHolder"));
          actual = current;
          if(imageMap.containsKey(actual))
          isPresent = true;
          else{
          imageMap.put(actual, new Date().toString());
          System.out.println("Image : " + actual + " appeared at : " + new Date().toString());
          }
          current = body.getCssValue("background-image");
          }
          }


          This gives you all details including fade out frequency. If your requirement is to get only Image load time, Then parse the acutal and current strings to compare only URL value







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 27 '18 at 12:41









          Bhargav MarpuBhargav Marpu

          1965




          1965













          • Thanks Bhargav. But one concern , image keeps changing randomly , consider first time we got img-1 and second time we got img-2 but third time we may get img-1 again .In this case our script is getting stopped because "is present" is changing to True and while loop is changing to False.I know its hard .Anyway thanks and i appreciate the way of code you written.

            – Adithya Pragada
            Nov 27 '18 at 14:40





















          • Thanks Bhargav. But one concern , image keeps changing randomly , consider first time we got img-1 and second time we got img-2 but third time we may get img-1 again .In this case our script is getting stopped because "is present" is changing to True and while loop is changing to False.I know its hard .Anyway thanks and i appreciate the way of code you written.

            – Adithya Pragada
            Nov 27 '18 at 14:40



















          Thanks Bhargav. But one concern , image keeps changing randomly , consider first time we got img-1 and second time we got img-2 but third time we may get img-1 again .In this case our script is getting stopped because "is present" is changing to True and while loop is changing to False.I know its hard .Anyway thanks and i appreciate the way of code you written.

          – Adithya Pragada
          Nov 27 '18 at 14:40







          Thanks Bhargav. But one concern , image keeps changing randomly , consider first time we got img-1 and second time we got img-2 but third time we may get img-1 again .In this case our script is getting stopped because "is present" is changing to True and while loop is changing to False.I know its hard .Anyway thanks and i appreciate the way of code you written.

          – Adithya Pragada
          Nov 27 '18 at 14:40















          0














          Each image has own unique "aria-label", you can use it.



              WebElement image = driver.findElement(By.id("ImagePlaceHolder"));
          String image_name = image.getAttribute("aria-label");


          To measure changing time you can use LocalDateTime and Duration.between(args)



          LocalDateTime timestamp1 = LocalDateTime.now();
          Long duration_in_seconds = Duration.between(timestamp1, timestamp2).toMillis() / 1000;


          Implemented JavaScript changes the image each 3 seconds. Not sure how will selenium handle it, didn't try it.






          share|improve this answer


























          • Thanks for your reply.But as per your code i will get just image name but i need how many images are there.So for that How i can loop if we do not have know number of images and we do not know after how many seconds will the image change.

            – Adithya Pragada
            Nov 27 '18 at 10:40











          • After page is loaded with first img, add the img name to an ArrayList. Then add each new img. Adding img to the array must be conditional to prevent doubling img names in the array. After "some time" just count element in that array. If I find some free time I'll try to create a full test.

            – pburgr
            Nov 27 '18 at 10:44
















          0














          Each image has own unique "aria-label", you can use it.



              WebElement image = driver.findElement(By.id("ImagePlaceHolder"));
          String image_name = image.getAttribute("aria-label");


          To measure changing time you can use LocalDateTime and Duration.between(args)



          LocalDateTime timestamp1 = LocalDateTime.now();
          Long duration_in_seconds = Duration.between(timestamp1, timestamp2).toMillis() / 1000;


          Implemented JavaScript changes the image each 3 seconds. Not sure how will selenium handle it, didn't try it.






          share|improve this answer


























          • Thanks for your reply.But as per your code i will get just image name but i need how many images are there.So for that How i can loop if we do not have know number of images and we do not know after how many seconds will the image change.

            – Adithya Pragada
            Nov 27 '18 at 10:40











          • After page is loaded with first img, add the img name to an ArrayList. Then add each new img. Adding img to the array must be conditional to prevent doubling img names in the array. After "some time" just count element in that array. If I find some free time I'll try to create a full test.

            – pburgr
            Nov 27 '18 at 10:44














          0












          0








          0







          Each image has own unique "aria-label", you can use it.



              WebElement image = driver.findElement(By.id("ImagePlaceHolder"));
          String image_name = image.getAttribute("aria-label");


          To measure changing time you can use LocalDateTime and Duration.between(args)



          LocalDateTime timestamp1 = LocalDateTime.now();
          Long duration_in_seconds = Duration.between(timestamp1, timestamp2).toMillis() / 1000;


          Implemented JavaScript changes the image each 3 seconds. Not sure how will selenium handle it, didn't try it.






          share|improve this answer















          Each image has own unique "aria-label", you can use it.



              WebElement image = driver.findElement(By.id("ImagePlaceHolder"));
          String image_name = image.getAttribute("aria-label");


          To measure changing time you can use LocalDateTime and Duration.between(args)



          LocalDateTime timestamp1 = LocalDateTime.now();
          Long duration_in_seconds = Duration.between(timestamp1, timestamp2).toMillis() / 1000;


          Implemented JavaScript changes the image each 3 seconds. Not sure how will selenium handle it, didn't try it.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 27 '18 at 10:31









          Matim

          630520




          630520










          answered Nov 27 '18 at 8:49









          pburgrpburgr

          467129




          467129













          • Thanks for your reply.But as per your code i will get just image name but i need how many images are there.So for that How i can loop if we do not have know number of images and we do not know after how many seconds will the image change.

            – Adithya Pragada
            Nov 27 '18 at 10:40











          • After page is loaded with first img, add the img name to an ArrayList. Then add each new img. Adding img to the array must be conditional to prevent doubling img names in the array. After "some time" just count element in that array. If I find some free time I'll try to create a full test.

            – pburgr
            Nov 27 '18 at 10:44



















          • Thanks for your reply.But as per your code i will get just image name but i need how many images are there.So for that How i can loop if we do not have know number of images and we do not know after how many seconds will the image change.

            – Adithya Pragada
            Nov 27 '18 at 10:40











          • After page is loaded with first img, add the img name to an ArrayList. Then add each new img. Adding img to the array must be conditional to prevent doubling img names in the array. After "some time" just count element in that array. If I find some free time I'll try to create a full test.

            – pburgr
            Nov 27 '18 at 10:44

















          Thanks for your reply.But as per your code i will get just image name but i need how many images are there.So for that How i can loop if we do not have know number of images and we do not know after how many seconds will the image change.

          – Adithya Pragada
          Nov 27 '18 at 10:40





          Thanks for your reply.But as per your code i will get just image name but i need how many images are there.So for that How i can loop if we do not have know number of images and we do not know after how many seconds will the image change.

          – Adithya Pragada
          Nov 27 '18 at 10:40













          After page is loaded with first img, add the img name to an ArrayList. Then add each new img. Adding img to the array must be conditional to prevent doubling img names in the array. After "some time" just count element in that array. If I find some free time I'll try to create a full test.

          – pburgr
          Nov 27 '18 at 10:44





          After page is loaded with first img, add the img name to an ArrayList. Then add each new img. Adding img to the array must be conditional to prevent doubling img names in the array. After "some time" just count element in that array. If I find some free time I'll try to create a full test.

          – pburgr
          Nov 27 '18 at 10:44


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53494892%2fwrite-a-automation-code-for-background-images%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)