From 2973c3fcbce231d2b1be813570521b8371fdc9c9 Mon Sep 17 00:00:00 2001 From: Sujeet Sreenivasan Date: Thu, 27 Mar 2014 15:29:45 -0700 Subject: [PATCH] Modify tests for CreateSeries Add test methods to rswebutil and make createseries call those functions passing in variables --- java/run_single_test.sh | 2 +- .../test/webdriver/CreateSeriesTestSuite.java | 90 +++++++++++++- .../test/webdriver/CreateShareinGb.java | 2 +- .../webdriver/CreateSnapshotFromShares.java | 109 ++--------------- .../rockstor/test/webdriver/NFSExport.java | 109 +++-------------- .../rockstor/test/webdriver/RsTestBase.java | 2 + .../rockstor/test/webdriver/RsWebUtil.java | 114 +++++++++++++++++- java/src/main/resources/config.properties | 2 +- 8 files changed, 223 insertions(+), 207 deletions(-) diff --git a/java/run_single_test.sh b/java/run_single_test.sh index dca409d..4e4617e 100755 --- a/java/run_single_test.sh +++ b/java/run_single_test.sh @@ -1,2 +1,2 @@ -mvn exec:java -Dexec.mainClass="org.junit.runner.JUnitCore" -Dexec.args="com.rockstor.test.webdriver.CreateShareinGb" +mvn exec:java -Dexec.mainClass="org.junit.runner.JUnitCore" -Dexec.args="com.rockstor.test.webdriver.CreateSeriesTestSuite" diff --git a/java/src/main/java/com/rockstor/test/webdriver/CreateSeriesTestSuite.java b/java/src/main/java/com/rockstor/test/webdriver/CreateSeriesTestSuite.java index 67ee3a6..6ab5724 100644 --- a/java/src/main/java/com/rockstor/test/webdriver/CreateSeriesTestSuite.java +++ b/java/src/main/java/com/rockstor/test/webdriver/CreateSeriesTestSuite.java @@ -1,14 +1,92 @@ package com.rockstor.test.webdriver; + import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -@RunWith(Suite.class) -@SuiteClasses({AddPoolRaid0with2Disks.class,CreateShareinGb.class, - SambaExport.class,NFSExport.class,CreateSnapshotFromShares.class - }) -public class CreateSeriesTestSuite { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FileInputStream; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; // Dropdown menu +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.ExpectedConditions;// Explicit Waits +import org.openqa.selenium.support.ui.WebDriverWait; +import org.apache.commons.io.FileUtils; // Screenshots +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; + +import com.rockstor.test.util.RSProps; +import com.rockstor.test.util.RsUtil; + +import java.io.IOException; +import java.util.List; +import java.util.Properties; + +//@RunWith(Suite.class) +//@SuiteClasses({AddPoolRaid0with2Disks.class,CreateShareinGb.class, + //SambaExport.class,NFSExport.class,CreateSnapshotFromShares.class + //}) + +public class CreateSeriesTestSuite extends RsTestBase { + + @Test + public void testCreate() throws Exception { + // Pool + String poolName = "pool_" + RsUtil.generateRandomString(10); + int raidLevel = 0; + // Share + String shareName = "share_" + RsUtil.generateRandomString(10); + int shareSizeGb = 1; + // Samba + String adminUser = "admin"; + boolean browsable = true; + boolean guestOk = false; + boolean readOnly = false; + String comment = "Samba share"; + // NFS + // Snapshot + String snapName = "snap_" + RsUtil.generateRandomString(10); + boolean snapVisible = true; + + try { + RsWebUtil.login(driver, RSProps.getProperty("username"), + RSProps.getProperty("password")); + + // Create Pool + RsWebUtil.createPool(driver, poolName, raidLevel); + + // Create Share + RsWebUtil.createShare(driver, poolName, shareName, shareSizeGb); + + // Create Samba export + RsWebUtil.createSambaExport(driver, shareName, adminUser, + browsable, guestOk, readOnly, comment); + + // Create NFS export + //RsWebUtil.createNfsExport(driver, shares, hostStr, adminHost, + //writable, sync) { + + // Create snapshot + RsWebUtil.createSnapshot(driver, shareName, snapName, snapVisible); + + // Logout + RsWebUtil.logout(driver); + + } catch(Exception e){ + handleException(e); + } + + } } -//CreateUserWebUI.class \ No newline at end of file +//CreateUserWebUI.class diff --git a/java/src/main/java/com/rockstor/test/webdriver/CreateShareinGb.java b/java/src/main/java/com/rockstor/test/webdriver/CreateShareinGb.java index 8ead5f1..05dfd8a 100644 --- a/java/src/main/java/com/rockstor/test/webdriver/CreateShareinGb.java +++ b/java/src/main/java/com/rockstor/test/webdriver/CreateShareinGb.java @@ -37,7 +37,7 @@ public void testShareSizeGb() throws Exception { RsWebUtil.login(driver, RSProps.getProperty("username"), RSProps.getProperty("password")); - String poolName = "pool1"; + String poolName = "p1"; // Create 3 shares for (int i=0; i < 3; i++) { diff --git a/java/src/main/java/com/rockstor/test/webdriver/CreateSnapshotFromShares.java b/java/src/main/java/com/rockstor/test/webdriver/CreateSnapshotFromShares.java index ddfe857..d16db61 100644 --- a/java/src/main/java/com/rockstor/test/webdriver/CreateSnapshotFromShares.java +++ b/java/src/main/java/com/rockstor/test/webdriver/CreateSnapshotFromShares.java @@ -21,121 +21,32 @@ import org.openqa.selenium.TakesScreenshot; import com.rockstor.test.util.RSProps; +import com.rockstor.test.util.RsUtil; import java.io.IOException; import java.util.List; import java.util.Properties; -public class CreateSnapshotFromShares { - - private static WebDriver driver; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - driver = new FirefoxDriver(); - } +public class CreateSnapshotFromShares extends RsTestBase { @Test public void testUserNoWebUI() throws Exception { + String shareName = "share1"; + String snapName = "snap_" + RsUtil.generateRandomString(10); + boolean visible = true; try{ - driver.get(RSProps.getProperty("RockstorVm")); - - //User Login Input Forms - WebElement username = driver.findElement( - By.id("username")); - username.sendKeys("admin"); - - WebElement password = driver.findElement( - By.id("password")); - password.sendKeys("admin"); - - WebElement submitButton = driver.findElement( - By.id("sign_in")); - submitButton.click(); - - // Select Storage from Navigation bar - WebElement systemNav = driver.findElement(By.id("storage_nav")); - systemNav.click(); - - - // Select shares from storage side bar - WebElement sharesNav = driver.findElement(By.xpath("//div[@id='sidebar-inner']/ul/li/a[contains(@href,'shares')]")); - sharesNav.click(); - - WebElement myWaitElement = (new WebDriverWait(driver, 150)) - .until(ExpectedConditions.elementToBeClickable(By.id("add_share"))); - - - // Share link - WebElement shareLink = driver.findElement(By.linkText("share3")); - shareLink.click(); - - // wait for newshare page to load - myWaitElement = (new WebDriverWait(driver, 150)) - .until(ExpectedConditions.elementToBeClickable(By.id("js-delete"))); - - //Select Snapshot from navigation - - WebElement snapNav = driver.findElement(By.xpath("//div/ul/li/a[contains(text(),'Snapshots')]")); - snapNav.click(); - - // Wait for snapshot page to load - myWaitElement = (new WebDriverWait(driver, 150)) - .until(ExpectedConditions.elementToBeClickable(By.id("js-snapshot-add"))); - - // Create snapshot - WebElement snapshotButton = driver.findElement(By.id("js-snapshot-add")); - snapshotButton.click(); - - ///Fill up Snapshot form - - //Snapshot Name - WebElement snapshotName = driver.findElement(By.id("snapshot-name")); - snapshotName.sendKeys("newsnapshot"); - - // Check box to make visible for users - WebElement makeVisible = driver.findElement(By.cssSelector("input[id='snapshot-visible']")); - makeVisible.click(); - - // Submit button - WebElement createSnapshot = driver.findElement(By.id("js-snapshot-save")); - createSnapshot.click(); - - // Wait for snapshot page to load - myWaitElement = (new WebDriverWait(driver, 150)) - .until(ExpectedConditions.elementToBeClickable(By.id("js-snapshot-add"))); - - //verify that snapshot is created - List verifySnapCreated = driver.findElements( - By.xpath("//*[@id='snapshots-table']/tbody/tr[td[contains(text(),'newsnapshot')]]")); - assertEquals(verifySnapCreated.size(), 1); - - - //Logout - WebElement logoutSubmit = driver.findElement( - By.id("logout_user")); - - logoutSubmit.click(); - - + RsWebUtil.login(driver, RSProps.getProperty("username"), + RSProps.getProperty("password")); + RsWebUtil.createSnapshot(driver, shareName, snapName, visible); + RsWebUtil.logout(driver); } - //catch any exceptions by taking screenshots catch(Exception e){ - File screenshotFile = ((TakesScreenshot)driver) - .getScreenshotAs(OutputType.FILE); - FileUtils.copyFile(screenshotFile, - new File(RSProps.getProperty("screenshotDir") - + "/" + this.getClass().getName()+".png")); - throw e; + handleException(e); } } - @AfterClass - public static void tearDownAfterClass() throws Exception { - driver.quit(); - } } diff --git a/java/src/main/java/com/rockstor/test/webdriver/NFSExport.java b/java/src/main/java/com/rockstor/test/webdriver/NFSExport.java index 424515e..8704595 100644 --- a/java/src/main/java/com/rockstor/test/webdriver/NFSExport.java +++ b/java/src/main/java/com/rockstor/test/webdriver/NFSExport.java @@ -18,113 +18,32 @@ import com.rockstor.test.util.RSProps; -public class NFSExport { - - private static WebDriver driver; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - driver = new FirefoxDriver(); - } +public class NFSExport extends RsTestBase { @Test public void nfsExport() throws Exception { + String shareName = "share1"; + String[] shares = new String[] {"share1"}; + String hostStr = "192.168.56.101"; + String adminHost = "192.168.56.101"; + boolean writable = true; + boolean sync = true; try{ - driver.get(RSProps.getProperty("RockstorVm")); - - //User Login Input Forms - WebElement username = driver.findElement( - By.id("username")); - username.sendKeys("admin"); - - WebElement password = driver.findElement( - By.id("password")); - password.sendKeys("admin"); - - WebElement submitButton = driver.findElement( - By.id("sign_in")); - submitButton.click(); - - // Select System from Navigation bar - WebElement systemNav = driver.findElement(By.id("storage_nav")); - systemNav.click(); - - // Select NFS from system side bar - WebElement usersNav = driver.findElement(By.xpath("//div[@class='subnav']/ul/li/a[contains(@href,'nfs-exports')]")); - usersNav.click(); - - // Wait for add nfs-export button to appear - WebElement myWaitElement = (new WebDriverWait(driver, 150)) - .until(ExpectedConditions.elementToBeClickable( - By.id("add-nfs-export"))); - - WebElement addSambaBtn = driver.findElement(By.id("add-nfs-export")); - addSambaBtn.click(); - - myWaitElement = (new WebDriverWait(driver, 150)) - .until(ExpectedConditions.elementToBeClickable( - By.id("create-nfs-export"))); - - // Create NFS Export + RsWebUtil.login(driver, RSProps.getProperty("username"), + RSProps.getProperty("password")); - // Fillup form + RsWebUtil.createNfsExport(driver, shares, hostStr, adminHost, + writable, sync); - //Select Share from combo box - Select shareCombobox = new Select(driver.findElement(By.id("shares"))); - shareCombobox.selectByValue("share2"); - - // Host String - WebElement hostString = driver.findElement(By.id("host_str")); - hostString.sendKeys("192.168.1.20"); - - // Writable - Select guestOk = new Select(driver.findElement(By.id("mod_choice"))); - guestOk.selectByIndex(1); - - // Sync - Select readOnly = new Select(driver.findElement(By.id("sync_choice"))); - readOnly.selectByIndex(0); - - submitButton = driver.findElement(By.id("create-nfs-export")); - submitButton.click(); - - //wait until the page loads - myWaitElement = (new WebDriverWait(driver, 150)) - .until(ExpectedConditions.elementToBeClickable( - By.id("add-nfs-export"))); - - /* WebElement element1 = driver.findElement(By.id("nfs-exports-table")); - List rowCollection = element1.findElements(By.xpath("//*[@id='nfs-exports-table']/tbody/tr/td[contains(.,"+hostString+")]")); + RsWebUtil.logout(driver); - - if(rowCollection.size() > 0) - { - assert true; - } - - else { - - assert false; - } - - */ - } - //catch any exceptions by taking screenshots catch(Exception e){ - File screenshotFile = ((TakesScreenshot)driver) - .getScreenshotAs(OutputType.FILE); - FileUtils.copyFile(screenshotFile, - new File(RSProps.getProperty("screenshotDir") - + "/" + this.getClass().getName()+".png")); - throw e; + handleException(e); } } - @AfterClass - public static void tearDownAfterClass() throws Exception { - driver.quit(); - } + } diff --git a/java/src/main/java/com/rockstor/test/webdriver/RsTestBase.java b/java/src/main/java/com/rockstor/test/webdriver/RsTestBase.java index a8a5410..a398f8a 100644 --- a/java/src/main/java/com/rockstor/test/webdriver/RsTestBase.java +++ b/java/src/main/java/com/rockstor/test/webdriver/RsTestBase.java @@ -18,6 +18,8 @@ public static void tearDownAfterClass() throws Exception { } public void handleException(Exception e) throws Exception { + e.printStackTrace(); + // take a screenshot String filename = this.getClass().getName()+".png"; RsWebUtil.takeScreenshot(driver, filename); throw e; diff --git a/java/src/main/java/com/rockstor/test/webdriver/RsWebUtil.java b/java/src/main/java/com/rockstor/test/webdriver/RsWebUtil.java index dc1eab8..da8520d 100644 --- a/java/src/main/java/com/rockstor/test/webdriver/RsWebUtil.java +++ b/java/src/main/java/com/rockstor/test/webdriver/RsWebUtil.java @@ -9,6 +9,8 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; @@ -82,7 +84,6 @@ public static void createPool(WebDriver driver, WebElement disksTable = driver.findElement(By.id("disks-table")); List diskRows = disksTable.findElement(By.tagName("tbody")) .findElements(By.tagName("tr")); - System.out.println("Number of free disks is " + diskRows.size()); if (diskRows.size() < 2) { throw new Exception("Not enough free disks to create a " + " Raid0 pool"); @@ -99,6 +100,14 @@ public static void createPool(WebDriver driver, //Submit the form WebElement createPool = driver.findElement(By.id("create_pool")); createPool.click(); + + // wait till pools page is loaded + addPool = driver.findElement(By.id("add_pool")); + // verify that row with poolName exists + List poolRow = driver.findElements( + By.xpath("//*[@id='pools-table']/tbody/tr[td[a[contains(text(),'" + + poolName + "')]]]")); + assertEquals(poolRow.size(),1); } @@ -139,8 +148,8 @@ public static void createShare(WebDriver driver, String poolName, shareSubmitButton.click(); WebElement shareRowToCheckSize = driver.findElement( - By.xpath("//*[@id='shares-table']/tbody/tr[td[contains(.," - + shareName + ")]]")); + By.xpath("//*[@id='shares-table']/tbody/tr[td[contains(.,'" + + shareName + "')]]")); assertTrue(shareRowToCheckSize.getText(),true); } @@ -175,7 +184,7 @@ public static void createSambaExport(WebDriver driver, String shareName, // Read only Select readOnlyEl = new Select(driver.findElement(By.id("read_only"))); - readOnlyEl.selectByIndex(1); + readOnlyEl.selectByIndex(0); //Comment WebElement commentEl = driver.findElement(By.id("comment")); @@ -184,8 +193,105 @@ public static void createSambaExport(WebDriver driver, String shareName, WebElement saveButton = driver.findElement(By.id("create-samba-export")); saveButton.click(); + // wait till samba page is loaded + driver.findElement(By.id("add-samba-export")); + + // verify that row with poolName exists + List sambaRows = driver.findElements( + By.xpath("//*[@id='samba-table']/tbody/tr[td[text() = '" + + shareName + "']]")); + assertEquals(sambaRows.size(),1); + } + + public static void createNfsExport(WebDriver driver, String[] shares, + String hostStr, String adminHost, boolean writable, boolean sync) { + + // Select System from Navigation bar + driver.findElement(By.id("storage_nav")).click(); + + // Select NFS from sidebar + driver.findElement(By.xpath("//div[@class='subnav']/ul/li/a[contains(@href,'nfs-exports')]")).click(); + + // Go to add nfs export form + driver.findElement(By.id("add-nfs-export")).click(); + // Create NFS Export + + //Select Share from combo box + Select shareCombobox = new Select(driver.findElement(By.id("shares"))); + for (int i=0; i < shares.length; i++) { + shareCombobox.selectByValue(shares[i]); + } + + // Host String + WebElement hostStrEl = driver.findElement(By.id("host_str")); + hostStrEl.sendKeys(hostStr); + + // Admin Host + WebElement adminHostEl = driver.findElement(By.id("admin_host")); + adminHostEl.sendKeys(adminHost); + + // Writable + Select writableEl = new Select(driver.findElement(By.id("mod_choice"))); + if (writable) { + writableEl.selectByValue("rw"); + } else { + writableEl.selectByValue("ro"); + } + + // Sync + Select syncEl = new Select(driver.findElement(By.id("sync_choice"))); + if (sync) { + syncEl.selectByValue("sync"); + } else { + syncEl.selectByValue("async"); + } + + WebElement submitButton = driver.findElement(By.id("create-nfs-export")); + submitButton.click(); + + } + + public static void createSnapshot(WebDriver driver, String shareName, + String snapName, boolean visible) { + + // Select Storage from Navigation bar + driver.findElement(By.id("storage_nav")).click(); + + // Select shares from storage side bar + driver.findElement(By.xpath("//div[@id='sidebar-inner']/ul/li/a[contains(@href,'shares')]")).click(); + + // Share link + driver.findElement(By.linkText(shareName)).click(); + + //Select Snapshot from navigation + driver.findElement(By.xpath("//div/ul/li/a[contains(text(),'Snapshots')]")).click(); + + // Create snapshot + WebElement snapshotButton = driver.findElement(By.id("js-snapshot-add")); + snapshotButton.click(); + + //Snapshot Name + WebElement snapshotName = driver.findElement(By.id("snapshot-name")); + snapshotName.sendKeys(snapName); + + // Check box to make visible for users + if (visible) { + WebElement makeVisible = driver.findElement(By.cssSelector("input[id='snapshot-visible']")); + makeVisible.click(); + } + + // Submit button + WebElement createSnapshot = driver.findElement(By.id("js-snapshot-save")); + createSnapshot.click(); + + //verify that snapshot is created + List verifySnapCreated = driver.findElements( + By.xpath("//*[@id='snapshots-table']/tbody/tr[td[contains(text(),'" + snapName + "')]]")); + assertEquals(verifySnapCreated.size(), 1); + } + } diff --git a/java/src/main/resources/config.properties b/java/src/main/resources/config.properties index 4ae3315..278da38 100644 --- a/java/src/main/resources/config.properties +++ b/java/src/main/resources/config.properties @@ -1,6 +1,6 @@ RockstorVm=https\://192.168.56.101 screenshotDir=output/screenshots -waitTimeout=30 +waitTimeout=10 username=admin password=admin