package com.softwareonpurpose.uinavigator;

import com.softwareonpurpose.uinavigator.driver.DefaultFirefoxInstantiation;
import com.softwareonpurpose.uinavigator.validators.BooleanValidator;
import com.softwareonpurpose.uinavigator.validators.ClassValidator;
import com.softwareonpurpose.uinavigator.validators.IntegerValidator;
import com.softwareonpurpose.uinavigator.validators.StringValidator;
import org.openqa.selenium.By;
import org.testng.annotations.Test;

@Test
public class UiHostTest extends TestBase {

    private static final String uri = "http://www.google.com";

    @Test
    public void getDefaultInstance() {
        Class expected = UiHost.class;
        Class actual = UiHost.getInstance().getClass();
        confirm(ClassValidator.getInstance(expected, actual).validate());
    }

    @Test(dependsOnMethods = "getDefaultInstance")
    public void load() {
        String domain = "www.google.com";
        String expected = String.format("https://%s", domain);
        UiHost.getInstance().load(String.format("http://%s", domain));
        String actual = UiHost.getInstance().getUri();
        confirm(StringValidator.getInstance(expected, actual).validate());
    }

    @Test(dependsOnMethods = "getDefaultInstance")
    public void findUiElement() {
        String expected = "ctr-p";
        final UiHost browser = UiHost.getInstance();
        browser.load("http://www.google.com");
        String actual = browser.findUiElement(By.id("viewport")).getAttribute("class");
        confirm(StringValidator.getInstance(expected, actual).validate());
    }

    @Test(dependsOnMethods = "getDefaultInstance")
    public void findUiElements() {
        Integer expected = 6;
        final UiHost browser = UiHost.getInstance();
        browser.load(uri);
        Integer actual = browser.findUiElements(By.className("_Gs")).size();
        confirm(IntegerValidator.getInstance(expected, actual).validate());
    }

    @Test(dependsOnMethods = "getDefaultInstance")
    public void waitUntilVisible() {
        UiHost browser = UiHost.getInstance();
        browser.load(uri);
        Boolean actual = browser.waitUntilVisible(By.name("btnK"));
        confirm(BooleanValidator.getInstance(true, actual).validate());
    }

    @Test(enabled = false, dependsOnMethods = "getDefaultInstance")
    public void getSpecifWebDriverInstance() {
        String expected = "Firefox";
        DriverInstantiation driverInstantiation = DefaultFirefoxInstantiation.getInstance();
        String actual = UiHost.getInstance(driverInstantiation).getDriverName();
        confirm(StringValidator.getInstance(expected, actual).validate());
    }

    @Test(dependsOnMethods = "getDefaultInstance")
    public void selectFrame() {
        String expected = "Log In";
        UiHost host = UiHost.getInstance();
        host.load("http:espn.go.com");
        UiElement.getInstance("'Login' link", UiElement.LocatorType.TAG, "a", UiElement.getInstance("'User' region", UiElement.LocatorType.CLASS, "user")).click();
        host.selectFrame("disneyid-iframe");
        String actual = UiHost.getInstance().findUiElement(By.className("btn-group")).getText();
        confirm(StringValidator.getInstance(expected, actual).validate());
    }

    @Test(dependsOnMethods = "getDefaultInstance")
    public void selectWindow() {
        String expected = null;
        UiHost host = UiHost.getInstance();
        host.load("http:espn.go.com");
        UiElement.getInstance("'Login' link", UiElement.LocatorType.TAG, "a", UiElement.getInstance("'User' region", UiElement.LocatorType.CLASS, "user")).click();
        host.selectFrame("disneyid-iframe");
        host.selectWindow();
        String actual = UiElement.getInstance("'Login' button", UiElement.LocatorType.CLASS, "btn-group").getText();
        confirm(StringValidator.getInstance(expected, actual).validate());
    }
}

@@ -430,16 +430,61 @@
 um.By;%0D%0A
+import org.testng.annotations.DataProvider;%0D%0A
 import o
@@ -629,24 +629,200 @@
 le.com%22;%0D%0A%0D%0A
+    @DataProvider%0D%0A    public static Object%5B%5D%5B%5D drivers() %7B%0D%0A        return new Object%5B%5D%5B%5D%7B%7B%0D%0A                DefaultFirefoxInstantiation.getInstance(), %22Firefox%22%7D%7D;%0D%0A    %7D%0D%0A%0D%0A
     @Test%0D%0A 
@@ -2534,245 +2534,167 @@
 est(
-enabled = false, dependsOnMethods = %22getDefaultInstance%22)%0D%0A    public void getSpecifWebDriverInstance() %7B%0D%0A        String expected = %22Firefox%22;%0D%0A        DriverInstantiation driverInstantiation = DefaultFirefoxInstantiation.getInstance();
+groups = %22under_development%22, dataProvider = %22drivers%22)%0D%0A    public void getSpecifWebDriverInstance(DriverInstantiation driverInstantiation, String expected) %7B
 %0D%0A  

Update test for specific webdriver to accommodate other browers