package ghostdriver;

import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.internal.Locatable;

import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class ElementQueryingTest extends BaseTest {
    @Test
    public void checkAttributesOnGoogleSearchBox() {
        WebDriver d = getDriver();

        d.get("http://www.google.com");
        WebElement el = d.findElement(By.cssSelector("input[name*='q']"));

        assertTrue(el.getAttribute("name").toLowerCase().contains("q"));
        assertTrue(el.getAttribute("type").toLowerCase().contains("text"));
        assertTrue(el.getAttribute("style").length() > 0);
        assertTrue(el.getAttribute("type").length() > 0);
    }

    @Test
    public void checkLocationAndSizeOfGoogleSearchBox() {
        WebDriver d = getDriver();
        d.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);

        d.get("http://www.bing.com");
        WebElement radio = d.findElement(By.cssSelector("input#nofilt[type='radio']"));
        WebElement radioLabel = d.findElement(By.cssSelector("label[for='nofilt']"));

        assertEquals(radio.getCssValue("color"), "rgb(0, 0, 0)");
        assertEquals(radioLabel.getText(), "Show all");
        assertEquals(radio.getAttribute("value"), "all");
        assertEquals(radio.getTagName(), "input");
        assertEquals(radio.isEnabled(), true);
        assertEquals(radio.isDisplayed(), true);
        assertEquals(radio.isSelected(), true);
        assertEquals(radio.getLocation(), new Point(215, 138));
        assertEquals(radio.getSize(), new Dimension(15, 15));
    }

    @Test
    public void scrollElementIntoView() {
        WebDriver d = getDriver();

        d.get("https://developer.mozilla.org/en/CSS/Attribute_selectors");
        WebElement aboutGoogleLink = d.findElement(By.partialLinkText("About MDN"));
        Point locationBeforeScroll = aboutGoogleLink.getLocation();
        Point locationAfterScroll = ((Locatable) aboutGoogleLink).getLocationOnScreenOnceScrolledIntoView();

        assertTrue(locationBeforeScroll.x >= locationAfterScroll.x);
        assertTrue(locationBeforeScroll.y >= locationAfterScroll.y);
    }
}

@@ -832,22 +832,20 @@
 ndSizeOf
-Google
+Bing
 SearchBo
@@ -1012,21 +1012,25 @@
 Element 
-radio
+searchBox
  = d.fin
@@ -1063,120 +1063,32 @@
 nput
-#nofilt%5Btype='radio'%5D%22));%0A        WebElement radioLabel = d.findElement(By.cssSelector(%22label%5Bfor='nofilt'%5D%22));%0A
+%5Bname*='q'%5D%22));%0A        
 %0A   
@@ -1101,29 +1101,33 @@
 ssertEquals(
-radio
+searchBox
 .getCssValue
@@ -1179,69 +1179,17 @@
 als(
-radioLabel.getText(), %22Show all%22);%0A        assertEquals(radio
+searchBox
 .get
@@ -1213,11 +1213,8 @@
 ), %22
-all
 %22);%0A
@@ -1230,29 +1230,33 @@
 ssertEquals(
-radio
+searchBox
 .getTagName(
@@ -1289,21 +1289,25 @@
 tEquals(
-radio
+searchBox
 .isEnabl
@@ -1340,21 +1340,25 @@
 tEquals(
-radio
+searchBox
 .isDispl
@@ -1397,61 +1397,17 @@
 als(
-radio.isSelected(), true);%0A        assertEquals(radio
+searchBox
 .get
@@ -1434,14 +1434,14 @@
 t(21
-5, 138
+8, 104
 ));%0A
@@ -1465,13 +1465,17 @@
 als(
-radio
+searchBox
 .get
@@ -1500,14 +1500,15 @@
 ion(
-15, 15
+389, 28
 ));%0A

correct bing.com test failures