Skip to content
Draft
Show file tree
Hide file tree
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
13 changes: 8 additions & 5 deletions junit-tests/src/test/java/org/testmonkeys/TestConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.testmonkeys;

import org.json.JSONObject;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.testmonkeys.maui.core.browser.Browser;
import org.testmonkeys.DriverFactory;

import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

Expand All @@ -35,6 +37,7 @@ public Properties loadTestProperties() throws IOException {

@Bean
@Scope("prototype")
//@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented code.

public Browser browser(@Value("${selenium.profile}") String seleniumProfile,
@Value("${browser.profile}") String browserProfile ) throws Exception {
if (seleniumProfile==null || seleniumProfile.isEmpty()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class HtmlElementsPageObject extends AbstractPage {
@ElementAccessor(elementName = "element5", byId = "hidden_input")
private Input hiddenInput;

@ElementAccessor(elementName = "element13NonExisting", byId = "element13NonExisting")
private Input nonExistingInput;

public Input firstName() {
return firstName;
}
Expand All @@ -50,4 +53,8 @@ public Input getNoDisplayInput() {
public Input getHiddenInput() {
return hiddenInput;
}

public Input getNonExistingInput() {
return nonExistingInput;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

import com.automation.remarks.junit.VideoRule;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.testmonkeys.DriverFactory;
import org.testmonkeys.TestConfiguration;
import org.testmonkeys.maui.core.browser.Browser;

import java.sql.Driver;

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = TestConfiguration.class)
abstract public class AbstractComponentTest {
Expand All @@ -28,8 +24,8 @@ public void cleanup() {
browser.quit();
}

@AfterClass
public static void cleanupClass() {
DriverFactory.stopLocals();
}
// @After
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented code

// public static void cleanupClass() {
// DriverFactory.stopLocals();
// }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.testmonkeys.webpages.tests.elements;

import org.hamcrest.Matchers;
import org.junit.Test;
import org.testmonkeys.webpages.tests.AbstractHtmlElementPageTest;

import java.time.Duration;
import java.time.Instant;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

Expand Down Expand Up @@ -32,4 +36,14 @@ public void isDisplayed_false_hidden() {
public void isDisplayed_true() {
assertThat("first name2 displayed", page.firstName2().isDisplayed(), is(true));
}

@Test
public void isDisplayed_elementNotPresent() {
Instant start = Instant.now();
assertThat("element not present is displayed", page.getNonExistingInput().isDisplayed(), is(false));
Instant end = Instant.now();
Duration executedDuration = Duration.between(start, end);
System.out.println(executedDuration);
assertThat("search was more or less instant", executedDuration.getSeconds(), Matchers.lessThan(2l));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public List<WebElement> findElements(Locator locator) {
return dynamicWaiter.until(webDriver -> webDriver.findElements(locator.getSeleniumLocator()));
}

@Override
public WebElement instantFind(Locator locator) {
return driver.findElement(locator.getSeleniumLocator());
}

private FluentWait<WebDriver> initWaitter(int timeout, int step, TimeUnit unit) {
return new FluentWait<>(this.driver)
.withTimeout(timeout, unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface Component extends LocatesElements {

WebElement find();

WebElement instantFind();

Browser getBrowser();

void setBrowser(Browser browser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface LocatesElements {
WebElement findElement(Locator locator);

List<WebElement> findElements(Locator locator);

WebElement instantFind(Locator locator);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public WebElement findElement(Locator locator) {
return browser.findElement(locator);
}

@Override
public WebElement instantFind(Locator locator) {
return browser.instantFind(locator);
}

@Override
public List<WebElement> findElements(Locator locator) {
return browser.findElements(locator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ public void setParent(LocatesElements parent) {
this.parent = parent;
}

@Override
public WebElement instantFind() {
if (parent == null)
webElement = browser.instantFind(locator);
else {
webElement = parent.instantFind(locator);
}
return webElement;
}

@Override
public WebElement instantFind(Locator locator) {
return instantFind().findElement(locator.getSeleniumLocator());
}

@Override
public WebElement find() {
if (webElement != null && isAlive(webElement)) {
Expand Down Expand Up @@ -153,7 +168,7 @@ public String toString() {
@Override
public boolean isDisplayed() {
try {
return find().isDisplayed();
return instantFind().isDisplayed();
} catch (Exception e) {
return false;
}
Expand Down