Search in sources :

Example 66 with BrowserInfo

use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.

the class TestMobileDeviceSelector method testCapabilitiesUpdateWithDriver.

/**
 * Test the update of driver capabilities when using browsers in local mode
 */
@Test(groups = { "ut" })
public void testCapabilitiesUpdateWithDriver() {
    // available devices
    List<MobileDevice> deviceList = new ArrayList<>();
    BrowserInfo chromeInfo = new BrowserInfo(BrowserType.CHROME, "47.0", null);
    chromeInfo.setDriverFileName("chromedriver.exe");
    deviceList.add(new MobileDevice("nexus 5", "1234", "android", "5.0", Arrays.asList(chromeInfo)));
    when(adbWrapper.getDeviceList()).thenReturn(deviceList);
    DesiredCapabilities requestedCaps = new DesiredCapabilities();
    requestedCaps.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus 5");
    requestedCaps.setCapability(MobileCapabilityType.BROWSER_NAME, "chrome");
    deviceSelector.setAndroidReady(true);
    deviceSelector.setIosReady(false);
    MutableCapabilities updatedCaps = deviceSelector.updateCapabilitiesWithSelectedDevice(requestedCaps, DriverMode.LOCAL);
    Assert.assertEquals(updatedCaps.getCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE), "chromedriver.exe");
}
Also used : MobileDevice(com.seleniumtests.browserfactory.mobile.MobileDevice) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) MutableCapabilities(org.openqa.selenium.MutableCapabilities) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 67 with BrowserInfo

use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.

the class TestMobileDeviceSelector method testCapabilitiesUpdateWithDriverNonLocal.

/**
 * Test the driver capabilities are not updated with driver executable when using browsers in non-local mode
 */
@Test(groups = { "ut" })
public void testCapabilitiesUpdateWithDriverNonLocal() {
    // available devices
    List<MobileDevice> deviceList = new ArrayList<>();
    BrowserInfo chromeInfo = new BrowserInfo(BrowserType.BROWSER, "47.0", null);
    chromeInfo.setDriverFileName("chromedriver2.exe");
    deviceList.add(new MobileDevice("nexus 5", "1234", "android", "5.0", Arrays.asList(chromeInfo)));
    when(adbWrapper.getDeviceList()).thenReturn(deviceList);
    DesiredCapabilities requestedCaps = new DesiredCapabilities();
    requestedCaps.setCapability(MobileCapabilityType.DEVICE_NAME, "Nexus 5");
    requestedCaps.setCapability(MobileCapabilityType.BROWSER_NAME, "browser");
    deviceSelector.setAndroidReady(true);
    deviceSelector.setIosReady(false);
    MutableCapabilities updatedCaps = deviceSelector.updateCapabilitiesWithSelectedDevice(requestedCaps, DriverMode.SAUCELABS);
    Assert.assertNull(updatedCaps.getCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE));
}
Also used : MobileDevice(com.seleniumtests.browserfactory.mobile.MobileDevice) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) MutableCapabilities(org.openqa.selenium.MutableCapabilities) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 68 with BrowserInfo

use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.

the class TestWebUIDriver method testDriverCreationInGrid.

/**
 * issue #280: check that selectedBrowserInfo is available in grid mode
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testDriverCreationInGrid() throws Exception {
    SeleniumTestsContextManager.getThreadContext().setBrowser("htmlunit");
    SeleniumTestsContextManager.getThreadContext().setWebDriverGrid("http://localhost:4444/wd/hub");
    SeleniumTestsContextManager.getThreadContext().setRunMode("grid");
    // set connector to simulate the driver creation on grid
    SeleniumTestsContextManager.getThreadContext().setSeleniumGridConnectors(Arrays.asList(gridConnector));
    when(gridConnector.getNodeUrl()).thenReturn("http://localhost:5555/");
    whenNew(SeleniumGridDriverFactory.class).withAnyArguments().thenReturn(gridDriverFactory);
    when(gridDriverFactory.createWebDriver()).thenReturn(drv1);
    when(gridDriverFactory.getSelectedBrowserInfo()).thenReturn(new BrowserInfo(BrowserType.HTMLUNIT, "1.1"));
    CustomEventFiringWebDriver ceDriver = (CustomEventFiringWebDriver) WebUIDriver.getWebDriver(true);
    Assert.assertNotNull(ceDriver.getBrowserInfo());
    Assert.assertEquals(ceDriver.getBrowserInfo().getVersion(), "1.1");
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 69 with BrowserInfo

use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.

the class TestSelectList method init.

@BeforeMethod(groups = { "ut" })
private void init() throws IOException {
    SeleniumTestsContextManager.getThreadContext().setBrowser("firefox");
    SeleniumTestsContextManager.getThreadContext().setExplicitWaitTimeout(1);
    SeleniumTestsContextManager.getThreadContext().setImplicitWaitTimeout(1);
    SeleniumTestsContextManager.getThreadContext().setReplayTimeout(2);
    eventDriver = spy(new CustomEventFiringWebDriver(driver));
    when(eventDriver.switchTo()).thenReturn(target);
    // standard select
    when(driver.findElement(By.id("select"))).thenReturn(element);
    when(element.getTagName()).thenReturn("select");
    when(element.isDisplayed()).thenReturn(true);
    when(element.findElements(By.tagName("option"))).thenReturn(Arrays.asList(option1, option2));
    // the way Select class search for text and value
    when(element.findElements(By.xpath(".//option[normalize-space(.) = \"opt1\"]"))).thenReturn(Arrays.asList(option1));
    when(element.findElements(By.xpath(".//option[normalize-space(.) = \"opt2\"]"))).thenReturn(Arrays.asList(option2));
    when(element.findElements(By.xpath(".//option[@value = \"opti1\"]"))).thenReturn(Arrays.asList(option1));
    when(element.findElements(By.xpath(".//option[@value = \"opti2\"]"))).thenReturn(Arrays.asList(option2));
    when(option1.getText()).thenReturn("opt1");
    when(option2.getText()).thenReturn("opt2");
    when(option1.getAttribute("value")).thenReturn("opti1");
    when(option2.getAttribute("value")).thenReturn("opti2");
    when(option1.getAttribute("index")).thenReturn("1");
    when(option2.getAttribute("index")).thenReturn("2");
    // when(driver.getCurrentUrl()).thenReturn("http://foo");
    // when(element.getSize()).thenReturn(new Dimension(10, 10));
    // when(element.getLocation()).thenReturn(new Point(5, 5));
    PowerMockito.mockStatic(WebUIDriver.class);
    when(WebUIDriver.getCurrentWebUiDriverName()).thenReturn("main");
    when(WebUIDriver.getWebDriver(anyBoolean(), eq(BrowserType.FIREFOX), eq("main"), isNull())).thenReturn(eventDriver);
    when(WebUIDriver.getWebDriver(anyBoolean())).thenReturn(eventDriver);
    when(eventDriver.executeScript("if (document.readyState === \"complete\") { return \"ok\"; }")).thenReturn("ok");
    when(eventDriver.getBrowserInfo()).thenReturn(new BrowserInfo(BrowserType.FIREFOX, "78.0"));
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 70 with BrowserInfo

use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.

the class TestUiElement method init.

@BeforeMethod(groups = { "ut" })
public void init() {
    UiElement.resetPageInformation();
    /*
		 * Create fields and labels
		 * 
		 * 								field4
		 * 
		 * 								label1Below
		 * 
		 *	field5		label1Right		field1/labelInside		label1Left		field3
		 * 
		 * 								label1Above
		 * 
		 * 								field2
		 * 
		 */
    // field to the left of "label1Left" and to the right of "label1Right"
    field1 = new Field(200, 300, 100, 120, null, "field");
    fieldWithLabel = new Field(100, 300, 100, 120, null, "field_with_label", field1);
    // field above "label1Above"
    field2 = new Field(200, 300, 300, 320, null, "field");
    // field to the right of "label1Left"
    field3 = new Field(600, 700, 100, 120, null, "field");
    // field above "label1Below"
    field4 = new Field(200, 300, 0, 20, null, "field");
    // field to the left of "label1Right"
    field5 = new Field(10, 60, 100, 120, null, "field");
    label1Right = new Label(100, 150, 100, 120, "label_with_field_on_right");
    label1Left = new Label(350, 400, 100, 120, "label_with_field_on_left");
    // label longer than field
    label1Above = new Label(200, 400, 200, 220, "label_with_field_above");
    // label shorter than field
    label1Below = new Label(200, 252, 70, 90, "label_with_field_below");
    label2 = new Label(100, 150, 0, 20, "label_without_field");
    labelInside = new Label(200, 250, 100, 120, "label_inside");
    PowerMockito.mockStatic(CustomEventFiringWebDriver.class);
    PowerMockito.mockStatic(WebUIDriver.class);
    PowerMockito.when(WebUIDriver.getWebDriver(anyBoolean())).thenReturn(driver);
    when(driver.getBrowserInfo()).thenReturn(new BrowserInfo(BrowserType.CHROME, "83.0"));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)71 Test (org.testng.annotations.Test)59 MockitoTest (com.seleniumtests.MockitoTest)53 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)53 ArrayList (java.util.ArrayList)23 List (java.util.List)19 BrowserType (com.seleniumtests.driver.BrowserType)18 HashMap (java.util.HashMap)14 MutableCapabilities (org.openqa.selenium.MutableCapabilities)9 GenericDriverTest (com.seleniumtests.GenericDriverTest)6 ChromeCapabilitiesFactory (com.seleniumtests.browserfactory.ChromeCapabilitiesFactory)5 EdgeCapabilitiesFactory (com.seleniumtests.browserfactory.EdgeCapabilitiesFactory)5 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 EnumMap (java.util.EnumMap)3 Map (java.util.Map)3 SkipException (org.testng.SkipException)3 FirefoxCapabilitiesFactory (com.seleniumtests.browserfactory.FirefoxCapabilitiesFactory)2 IECapabilitiesFactory (com.seleniumtests.browserfactory.IECapabilitiesFactory)2 MobileDevice (com.seleniumtests.browserfactory.mobile.MobileDevice)2