Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/test/java/com/lazerycode/selenium/util/QueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void returnsAValidSelectElement() {
when(MOCKED_WEB_ELEMENT_FOR_DEFAULT.getTagName()).thenReturn("select");

Query query = new Query().defaultLocator(DEFAULT_LOCATOR);
initQueryObject(query);
initQueryObject2(query);
Select element = query.findSelectElement();

assertThat(element).isInstanceOf(Select.class);
Expand All @@ -74,7 +74,7 @@ public void returnsAValidSelectElement() {
public void returnsDefaultLocator() {

Query query = new Query().defaultLocator(DEFAULT_LOCATOR);
initQueryObject(query);
initQueryObject2(query);

assertThat(query.by()).isEqualTo(DEFAULT_LOCATOR);
}
Expand All @@ -83,7 +83,7 @@ public void returnsDefaultLocator() {
public void returnsChromeLocatorIfSet() {

Query query = new Query().defaultLocator(DEFAULT_LOCATOR);
initQueryObject(query);
initQueryObject2(query);
query.addSpecificLocator(BrowserType.GOOGLECHROME, CHROME_LOCATOR);

assertThat(query.by()).isEqualTo(CHROME_LOCATOR);
Expand All @@ -93,7 +93,7 @@ public void returnsChromeLocatorIfSet() {
public void checkAlternateLocatorIsCaseInsensitiveWithUpper() {

Query query = new Query().defaultLocator(DEFAULT_LOCATOR);
initQueryObject(query);
initQueryObject2(query);
query.addSpecificLocator(BrowserType.GOOGLECHROME.toUpperCase(), CHROME_LOCATOR);

assertThat(query.by()).isEqualTo(CHROME_LOCATOR);
Expand All @@ -103,7 +103,7 @@ public void checkAlternateLocatorIsCaseInsensitiveWithUpper() {
public void checkAlternateLocatorIsCaseInsensitiveWithLower() {

Query query = new Query().defaultLocator(DEFAULT_LOCATOR);
initQueryObject(query);
initQueryObject2(query);
query.addSpecificLocator(BrowserType.GOOGLECHROME.toLowerCase(), CHROME_LOCATOR);

assertThat(query.by()).isEqualTo(CHROME_LOCATOR);
Expand All @@ -113,7 +113,7 @@ public void checkAlternateLocatorIsCaseInsensitiveWithLower() {
public void returnsDefaultLocatorIfDifferentBrowserIsSet() {

Query query = new Query().defaultLocator(DEFAULT_LOCATOR);
initQueryObject(query);
initQueryObject2(query);
query.addSpecificLocator(BrowserType.FIREFOX, FIREFOX_LOCATOR);

assertThat(query.by()).isEqualTo(DEFAULT_LOCATOR);
Expand All @@ -123,7 +123,7 @@ public void returnsDefaultLocatorIfDifferentBrowserIsSet() {
public void returnsWebElement() {

Query query = new Query().defaultLocator(DEFAULT_LOCATOR);
initQueryObject(query);
initQueryObject2(query);
WebElement element = query.findWebElement();

assertThat(element).isEqualTo(MOCKED_WEB_ELEMENT_FOR_DEFAULT);
Expand All @@ -143,7 +143,7 @@ public void findReturnsWebElement() {
public void returnsWebElementList() {

Query query = new Query().defaultLocator(DEFAULT_LOCATOR);
initQueryObject(query);
initQueryObject2(query);
List<WebElement> element = query.findWebElements();

assertThat(element).isEqualTo(MOCKED_WEB_ELEMENT_LIST_FOR_DEFAULT);
Expand Down Expand Up @@ -183,15 +183,15 @@ public void returnsMobileElementList() {
public void findMobileElementThrowsUnsupportedOperationExceptionIfPlatformIsNotAMobileType() {

Query query = new Query().defaultLocator(DEFAULT_LOCATOR);
initQueryObject(query);
initQueryObject2(query);
query.findMobileElement();
}

@Test(expected = UnsupportedOperationException.class)
public void findMobileElementThrowsUnsupportedOperationExceptionIfPlatformIsAGenericName() {

Query query = new Query().defaultLocator(DEFAULT_LOCATOR);
initQueryObject(query);
initQueryObject2(query);
query.findMobileElement();
}

Expand All @@ -216,6 +216,19 @@ private void initQueryObject(Query queryObject) {
queryObject.usingDriver(mockedWebDriver);
}

private void initQueryObject2(Query queryObject) {
Capabilities mockedCapabilities = mock(Capabilities.class);
when(mockedCapabilities.getBrowserName()).thenReturn(BrowserType.GOOGLECHROME);
when(mockedCapabilities.getCapability("automationName")).thenReturn(Platform.YOSEMITE);

RemoteWebDriver mockedWebDriver = mock(RemoteWebDriver.class);
when(mockedWebDriver.getCapabilities()).thenReturn(mockedCapabilities);
when(mockedWebDriver.findElement(DEFAULT_LOCATOR)).thenReturn(MOCKED_WEB_ELEMENT_FOR_DEFAULT);
when(mockedWebDriver.findElements(DEFAULT_LOCATOR)).thenReturn(MOCKED_WEB_ELEMENT_LIST_FOR_DEFAULT);

queryObject.usingDriver(mockedWebDriver);
}

private void initQueryObjectWithAppiumAndroid(Query queryObject) {
Capabilities mockedCapabilities = mock(Capabilities.class);
when(mockedCapabilities.getBrowserName()).thenReturn("");
Expand Down