Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WINDUP-2260 Changes to have the tests to work with a remote RHAMT instance #4

Merged
merged 3 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>org.jboss.windup.web</groupId>
<artifactId>windup-selenium-tests</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.2.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Windup Selenium Tests</name>
Expand Down
62 changes: 6 additions & 56 deletions src/test/java/org/jboss/windup/web/selenium/AnalyzeProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
public class AnalyzeProject extends CommonProject {

public AnalyzeProject() throws InterruptedException {

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("header-logo")));
waitForProjectList();

navigateProject("Selenium02Test");
waitForProjectLoad();
Expand Down Expand Up @@ -59,37 +57,6 @@ public void navigateTo(int index) throws InterruptedException {
}
}

/**
* from the project list screen this will navigate to whichever project is given
* by the name
*
* @param projName
* the exact string form of the project name
* @return true if the project is found
*/
public boolean navigateProject(String projName) {
// driver.navigate().to("http://127.0.0.1:8080/rhamt-web/project-list");
int x = 1;
while (true) {
try {
WebElement proj = driver
.findElement(By.xpath("(//*[@class='list-group-item project-info tile-click'])[" + x + "]"));

WebElement title = proj.findElement(By.cssSelector(
"div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-child(1)"));
if (title.getText().equals(projName)) {
title.click();
return true;
}
x++;
continue;
} catch (NoSuchElementException e) {
break;
}
}
return false;
}

/**
* this switches the tab on the window
*
Expand Down Expand Up @@ -742,9 +709,7 @@ private ArrayList<Integer> sortIntDesc(ArrayList<Integer> list) {
*
* @return true if the expansion of the first issue is complete
*/
public boolean

clickFirstIssue() throws InterruptedException{
public boolean clickFirstIssue() throws InterruptedException{
WebElement table = driver.findElement(By.cssSelector("table.tablesorter:nth-child(1)"));
WebElement body = table.findElement(By.cssSelector("tbody"));
WebElement issue = body.findElement(By.cssSelector("tr:nth-child(1)"));
Expand Down Expand Up @@ -773,6 +738,9 @@ private ArrayList<Integer> sortIntDesc(ArrayList<Integer> list) {
int x = 1;
while (true) {
try {
// TODO: fix this sleep in a better way
Thread.sleep(5000);
wait.until(ExpectedConditions.visibilityOf(body.findElement(By.cssSelector("tr:nth-child(" + x + ")"))));
WebElement file = body.findElement(By.cssSelector("tr:nth-child(" + x + ")"));
WebElement incident = file.findElement(By.cssSelector("td.text-right"));
total += Integer.valueOf(incident.getText());
Expand Down Expand Up @@ -1226,27 +1194,9 @@ public void submitFeedback() {
modalYes.click();
}

/**
* closes the browser
*/
public void closeDriver() {
driver.quit();
}

public void waitForProjectLoad()
{

WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".activated-item")));

}

public void waitForTabLoad()
{
//try increasing this from 10 seconds
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("ul.nav.navbar-nav li.active")));

}

}
}
55 changes: 4 additions & 51 deletions src/test/java/org/jboss/windup/web/selenium/AppLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

public class AppLevel extends CommonProject {

public AppLevel() throws InterruptedException {

WebElement header = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id("header-logo")));

public AppLevel()
{
waitForProjectList();
}

/**
Expand Down Expand Up @@ -55,34 +53,6 @@ public void switchTab(int index) {
WebElement tab = tabs.findElement(By.cssSelector("li:nth-child(" + index + ")"));
tab.click();
}

/**
* from the project list screen this will navigate to whichever project is given by the name
* @param projName the exact string form of the project name
* @return true if the project is found
*/
public boolean navigateProject(String projName) {
// driver.navigate().to("http://127.0.0.1:8080/rhamt-web/project-list");
int x = 1;
while (true) {
try {
WebElement proj = driver
.findElement(By.xpath("(//*[@class='list-group-item project-info tile-click'])[" + x + "]"));

WebElement title = proj.findElement(By.cssSelector(
"div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-child(1)"));
if (title.getText().equals(projName)) {
title.click();
return true;
}
x++;
continue;
} catch (NoSuchElementException e) {
break;
}
}
return false;
}

/**
* this method will navigate to a different tab based on the string passed in
Expand Down Expand Up @@ -719,21 +689,4 @@ public String feedbackRadioButton() {
}
return "null";
}

/**
* closes the browser
*/
public void closeDriver() {
driver.quit();
}

public void waitForProjectLoad()
{

WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".activated-item")));


}

}
}
93 changes: 91 additions & 2 deletions src/test/java/org/jboss/windup/web/selenium/CommonProject.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,118 @@
package org.jboss.windup.web.selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public abstract class CommonProject {

public static final String RHAMT_BASE_URL_PROPERTY = "baseUrl";
public static final String WITH_LOGIN_PROPERTY = "withLogin";
public static final String HEADLESS_PROPERTY = "headless";
private static final String RHAMT_BASE_URL_DEFAULT = "http://127.0.0.1:8080/";
protected WebDriver driver;
private final String rhamtBaseUrl;
private final boolean withLogin;
private final boolean headless;

public CommonProject()
{
rhamtBaseUrl = System.getProperty(RHAMT_BASE_URL_PROPERTY, RHAMT_BASE_URL_DEFAULT);
withLogin = System.getProperty(WITH_LOGIN_PROPERTY) != null;
headless = Boolean.parseBoolean(System.getProperty(HEADLESS_PROPERTY, "true"));

// Create a new instance of the driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");

ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
if (headless) options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
options.addArguments("--allow-insecure-localhost");
options.addArguments("--networkConnectionEnabled");
driver = new ChromeDriver(options);

// opens up the browser
driver.get("http://127.0.0.1:8080/");
driver.get(rhamtBaseUrl);
if (withLogin)
{
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("kc-logo-wrapper")));
login();
}
}

public String getRhamtBaseUrl() {
return rhamtBaseUrl;
}

public void login()
{
WebElement username = driver.findElement(By.id("username"));
username.sendKeys("rhamt");
WebElement password = driver.findElement(By.id("password"));
password.sendKeys("password");
WebElement loginButton = driver.findElement(By.id("kc-login"));
loginButton.click();
}

public void waitForProjectList()
{
WebElement header = (new WebDriverWait(driver, 20))
.until(ExpectedConditions.presenceOfElementLocated(By.className("projects-list")));
}

public void waitForNoProjectWelcomePage()
{
WebElement header = (new WebDriverWait(driver, 20))
.until(ExpectedConditions.presenceOfElementLocated(By.tagName("wu-no-projects-welcome")));
}

public void waitForProjectLoad()
{
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".activated-item")));
}

/**
* from the project list screen this will navigate to whichever project is given by the name
* @param projName the exact string form of the project name
* @return true if the project is found
*/
public boolean navigateProject(String projName) {
int x = 1;
while (true) {
try {
WebElement proj = driver
.findElement(By.xpath("(//*[@class='list-group-item project-info tile-click'])[" + x + "]"));

WebElement title = proj.findElement(By.cssSelector(
"div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-child(1)"));
if (title.getText().equals(projName)) {
title.click();
return true;
}
x++;
continue;
} catch (NoSuchElementException e) {
break;
}
}
return false;
}


/**
* closes the browser
*/
public void closeDriver() {
driver.quit();
}
}