yashaka

Untitled

Aug 20th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.93 KB | None | 0 0
  1. package com.tasj.b_how_selenide_waits_and_conditions_work;
  2.  
  3. import com.codeborne.selenide.Condition;
  4. import com.codeborne.selenide.Configuration;
  5. import org.junit.Test;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebElement;
  8.  
  9. import static com.codeborne.selenide.Condition.text;
  10. import static com.codeborne.selenide.Condition.visible;
  11. import static com.codeborne.selenide.Selenide.$;
  12. import static com.codeborne.selenide.Selenide.$$;
  13. import static com.codeborne.selenide.Selenide.open;
  14.  
  15. /**
  16.  * Created by yashaka on 6/28/15.
  17.  */
  18. public class SelenideGoogleSearchTest {
  19.  
  20.     @Test
  21.     public void testTextSearch(){
  22.         open("http://google.com/ncr");
  23. //        Configuration.timeout = 8000;
  24.  
  25.         /*
  26.             Selenide Implements a Command Pattern. What is something like:
  27.                                               ~   robot.do(command)
  28.          */
  29. //      $(By.name("q")).waitUntil(visible, 8000);
  30.         $(By.name("q")).shouldBe(visible); // ~ element.check(whatToCheck);
  31.         /*                  |
  32.                      START>>
  33.                             |
  34.                             remember START_TIME,
  35.            /--> START_WAIT> |
  36.           /                 IF (CURRENT_TIME() - START_TIME) > TIMEOUT' THEN THROW_ERROR
  37.          |                  ELSE                                             |
  38.          ^                  |                                                EXIT(FAILED)
  39.          |                  calls something like: visible.apply($(By.name("q")))
  40.          |                                                  |
  41.          |                                                  calls $(By.name("q")).isDisplayed()
  42.          |                                                                         |
  43.          ^                                                                         IF_ returned true THEN exit normally
  44.          |                                                                                        (~ "assertion passed")
  45.          |                                                                          /                     |
  46.          |                                                                         /                      EXIT(PASSED)
  47.          |                                                                        ELSE'' sleep(100ms),
  48.          \-<------------------------<--------------------------<------------------------<GOTO START_WAIT
  49.  
  50.  
  51.  
  52.              ' TIMEOUT equals to 4s by default
  53.              '' ELSE means: OR returned false OR SOME''' exception is thrown
  54.              ''' SOME means: some predefined exceptions normally thrown by webdriver when element is not found.
  55.                             these exceptions are listed in the implementation of shouldBe method.
  56.          */
  57.  
  58.  
  59.         $(By.name("q")).setValue("selenium").pressEnter();
  60.         $$(".srg>li.g").get(9).shouldHave(text("A browser automation framework and ecosystem"));
  61.     }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment