package automationTests; import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.net.MalformedURLException; import java.util.Calendar; import java.util.HashMap; import java.util.List; import org.junit.AfterClass; import org.junit.Test; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.Assert; import org.junit.BeforeClass; import org.openqa.selenium.By; import org.openqa.selenium.Keys; 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.interactions.Actions; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.JSONValue; import java.util.Map; public class UsersTest{ WebDriver driver; static APIClient client; static long runId; // static String Url = System.getenv("CLOUD_SDK_URL"); // static String trUser = System.getenv("TR_USER"); // static String trPwd = System.getenv("TR_PWD"); // static String cloudsdkUser = "support@example.com"; // static String cloudsdkPwd="support"; @BeforeClass public static void startTest() throws Exception { client = new APIClient("https://telecominfraproject.testrail.com"); client.setUser("syama.devi@connectus.ai"); client.setPassword("Connect123$"); JSONArray c = (JSONArray) client.sendGet("get_runs/5"); runId = new Long(0); Calendar cal = Calendar.getInstance(); //Months are indexed 0-11 so add 1 for current month int month = cal.get(Calendar.MONTH) + 1; String day = Integer.toString(cal.get(Calendar.DATE)); if (day.length()<2) { day = "0"+day; } String date = "UI Automation Run - " + day + "/" + month + "/" + cal.get(Calendar.YEAR); for (int a = 0; a < c.size(); a++) { if (((JSONObject) c.get(a)).get("name").equals(date)) { runId = (Long) ((JSONObject) c.get(a)).get("id"); } } } public void launchBrowser() { System.setProperty("webdriver.chrome.driver", "/home/netex/nightly_sanity/ui-scripts/chromedriver"); // System.setProperty("webdriver.chrome.driver", "/Users/mohammadrahman/Downloads/chromedriver"); ChromeOptions options = new ChromeOptions(); options.addArguments("--no-sandbox"); options.addArguments("--headless"); options.addArguments("--window-size=1920,1080"); driver = new ChromeDriver(options); driver.get("https://wlan-ui.qa.lab.wlan.tip.build"); } void closeBrowser() { driver.close(); } public void logIn() { driver.findElement(By.id("login_email")).sendKeys("support@example.com"); driver.findElement(By.id("login_password")).sendKeys("support"); driver.findElement(By.xpath("//*[@id=\"login\"]/button/span")).click(); } public void failure(int testId) throws MalformedURLException, IOException, APIException { driver.close(); Map data = new HashMap(); data.put("status_id", new Integer(5)); data.put("comment", "Fail"); JSONObject r = (JSONObject) client.sendPost("add_result_for_case/"+runId+"/"+testId, data); } public void accountsScreen(int testId) throws Exception { try { driver.findElement(By.linkText("Users")).click(); } catch (Exception E) { failure(testId); fail("Fail"); } } public void addAccountButton(int testId) throws MalformedURLException, IOException, APIException { try { Actions act = new Actions(driver); act.moveToElement(driver.findElement(By.cssSelector("[title^='addaccount']"))).click().perform(); } catch (Exception E) { failure(testId); fail("Fail"); } } public void verifyAddAccountPopup(int testId) throws MalformedURLException, IOException, APIException { Map data = new HashMap(); try { if (driver.findElement(By.id("rcDialogTitle0")).getText().equals("Add User")) { //pass } else { failure(testId); fail(); } } catch (Exception E) { failure(testId); fail("Fail"); } } public void addAccount(String account, String password, String confirmPassword, int testId) throws MalformedURLException, IOException, APIException { try { addAccountButton(testId); Actions browser = new Actions(driver); browser.sendKeys(Keys.TAB).perform(); browser.sendKeys(Keys.TAB).perform(); browser.sendKeys(account).perform(); browser.sendKeys(Keys.TAB).perform(); browser.sendKeys(Keys.TAB).perform(); browser.sendKeys(password).perform(); browser.sendKeys(Keys.TAB).perform(); browser.sendKeys(confirmPassword).perform(); browser.sendKeys(Keys.TAB).perform(); browser.sendKeys(Keys.TAB).perform(); browser.sendKeys(Keys.ENTER).perform(); } catch (Exception E) { failure(testId); fail("Fail"); } } public void blankEmailWarning(int testId) throws Exception { try { if (driver.findElement(By.cssSelector("[role^='alert']")).getText().equals("Please input your e-mail")) { //pass } else { failure(testId); fail("Incorrect warning displayed"); } } catch (Exception E) { failure(testId); fail("No warning displayed"); } } public void invalidPasswordsWarning(int testId) throws Exception { try { if (driver.findElement(By.cssSelector("[role^='alert']")).getText().equals("The two passwords do not match")) { //pass } else { failure(testId); fail("Incorrect warning displayed"); } } catch (Exception E) { failure(testId); fail("No warning displayed"); } } public void invalidEmailWarning(int testId) throws Exception { try { if (driver.findElement(By.cssSelector("[role^='alert']")).getText().equals("The input is not a valid e-mail")) { //pass } else { failure(testId); fail("Incorrect error displayed"); } } catch (Exception E) { failure(testId); fail("No error displayed"); } } public void editAccount(String oldName, String newName, int testId) throws Exception { try { WebElement tbl = driver.findElement(By.xpath("//table")); List rows = tbl.findElements(By.tagName("tr")); boolean found = false; //row iteration breakP: for(int i=0; i cols = rows.get(i).findElements(By.tagName("td")); //column iteration for(int j=0; j rows = tbl.findElements(By.tagName("tr")); boolean found = false; //row iteration breakP: for(int i=0; i cols = rows.get(i).findElements(By.tagName("td")); //column iteration for(int j=0; j rows = tbl.findElements(By.tagName("tr")); boolean found = false; //row iteration for(int i=0; i cols = rows.get(i).findElements(By.tagName("td")); //column iteration for(int j=0; j