Skip to content

Commit

Permalink
Add webdriver's timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
artbez committed Feb 26, 2017
1 parent e77cadb commit a001a6d
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 55 deletions.
16 changes: 0 additions & 16 deletions ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
import com.qreal.wmp.uitesting.exceptions.WrongAuthException;
import com.qreal.wmp.uitesting.services.Auther;
import com.qreal.wmp.uitesting.services.Opener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PageLoader {

private static final Logger logger = LoggerFactory.getLogger(PageLoader.class);

private final PageFactory pageFactory;

private final Opener opener;
Expand All @@ -25,25 +21,13 @@ public PageLoader(PageFactory pageFactory, Opener opener, Auther auther) {
/** Loads and returns requested page with default authentication. */
public <T> T load(Page page) {
opener.open(page.getIdentify());
// wait for load
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
return getPage(page);
}

/** Loads and returns requested page with login and password. */
public <T> T load(Page page, String username, String password) throws WrongAuthException {
auther.auth(username, password);
opener.open(page.getIdentify());
// wait for load
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
return getPage(page);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;

import java.util.concurrent.TimeUnit;

/** Creates beans for Spring needs. **/
@Configuration
@PropertySource("classpath:pages.properties")
Expand All @@ -35,6 +37,10 @@ public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderCon
public WebDriver webDriver() {
ChromeDriverManager.getInstance().setup();
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS);
WebDriverRunner.setWebDriver(driver);
return driver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public void setProperty(final SelenideElement element, final String propertyName
public String getProperty(final SelenideElement element, final String propertyName) throws NoSuchElementException {
$(By.cssSelector(SELECTOR)).click();
element.click();
try {
Thread.sleep(300);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
SelenideElement property = getInputOfElement(propertyName);
logger.info("Get value of preperty {}", propertyName);
if (property.attr("class").equals("input-group")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ private SceneImpl(WebDriver webDriver) {
createDiv("SceneWindowHorSize") + createDiv("SceneWindowVerSize")
);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
sceneWindow = SceneWindowImpl.getSceneWindow(this, webDriver, SELECTOR);
blockProvider = BlockProvider.getBlockProvider(sceneWindow, SELECTOR);
linkProvider = LinkProvider.getLinkProvider(SELECTOR, webDriver);
Expand Down Expand Up @@ -148,11 +143,6 @@ private void removeSceneElement(SceneElement sceneElement) throws ElementNotOnTh
sceneWindow.focus(sceneElement.getCoordinateOnScene());
logger.info("Remove element {} form scene", sceneElement.getInnerSeleniumElement().toString());
new Actions(webDriver).contextClick(sceneElement.getInnerSeleniumElement()).perform();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
SelenideElement contextMenu = $(By.id("scene-context-menu"));
if (!contextMenu.is(Condition.visible)) {
logger.info("Context menu " + contextMenu + " is not visible. Try to focus again. " );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
import com.qreal.wmp.uitesting.dia.scene.Coordinate;
import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException;
import org.openqa.selenium.By;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.codeborne.selenide.Selenide.$;

public class Link extends SceneElementImpl {

private static final Logger logger = LoggerFactory.getLogger(Link.class);

public static final String CLASS_NAME = "link";

private static final String ARROWHEAD = "marker-arrowheads";
Expand All @@ -27,11 +23,6 @@ public class Link extends SceneElementImpl {
public Link(String name, SelenideElement innerSeleniumObject) {
super(innerSeleniumObject);
this.name = name;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
this.source = new SceneElementImpl($(innerSeleniumObject
.find(By.className(ARROWHEAD))).find(By.cssSelector(":nth-child(1)"))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,6 @@ public void focus(final Coordinate coordinate) {
"canvas.scrollTop = " + Math.max(0, (coordinate.getYAbsolute() - sizeVer / 2)) + ";"
);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}

/*
focusHelper.horizontalWindowMovement(coordinate.getXAbsolute());
focusHelper.verticalWindowMovement(coordinate.getYAbsolute());
*/
}

@Contract("_, _, _ -> !null")
Expand All @@ -116,11 +106,6 @@ public void updateCanvasInfo() {
"$('#SceneWindowVerSize').html(BB.bottom - BB.top);"
);
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
}

// todo: make it waits real time until action is completed
Expand Down

0 comments on commit a001a6d

Please sign in to comment.