mil.dod.th.ose.gui.integration/src/mil/dod/th/ose/gui/integration/webapp/asset/TestAssetCommands.java
@Test
    public void testAddDeleteParameterButton() throws InterruptedException, ExecutionException, TimeoutException
    {
        AssetCommandHelper.clickAccordionPanel(m_Driver, ASSET_NAME, "Capture Image", ExpandCollapse.EXPAND);
        
        List<WebElement> tableRows = getParameterTableRows(AssetCommandHelper.
                getAssetCommandPanel(m_Driver, ASSET_NAME));
        
        final int rowCount = tableRows.size();
        
        //find an add button
        for (WebElement row : tableRows)
        {
            List<WebElement> thirdTd = row.findElements(By.cssSelector("td:nth-child(3)"));
            
            if (thirdTd.size() > 0)
            {
                //find what it contains. used the findElements method to avoid the NoSuchElementException
                //so lists should always be a size of one or empty.
                List<WebElement> buttons = thirdTd.get(0).findElements(By.cssSelector("button"));
                
                if (buttons.size() > 0)
                {
                    assertThat(buttons.get(0).getText(), is("Add"));
                    buttons.get(0).click();
                    break;
                }
            }
        }
        
        //Fluent wait used to wait for the parameter table to be updated when adding or deleting a parameter.
        Wait<WebDriver> fwait = new FluentWait<WebDriver>(m_Driver).withTimeout(30, TimeUnit.SECONDS).
                pollingEvery(1, TimeUnit.SECONDS).ignoring(StaleElementReferenceException.class, 
                        NoSuchElementException.class);
        
        //Fluent wait needed because it may take a second for the table to be updated when a parameter is removed.
        fwait.until(new ExpectedCondition<Boolean>()
        {
            @Override
            public Boolean apply(WebDriver driver)
            {
                List<WebElement> tableRows = getParameterTableRows(AssetCommandHelper.
                        getAssetCommandPanel(m_Driver, ASSET_NAME));
                return tableRows.size() > rowCount;
            }
        });
        
        tableRows = getParameterTableRows(AssetCommandHelper.
                getAssetCommandPanel(m_Driver, ASSET_NAME));
        
        //find the delete button that was the add button
        for (WebElement row : tableRows)
        {
            List<WebElement> thirdTd = row.findElements(By.cssSelector("td:nth-child(3)"));
            
            if (thirdTd.size() > 0)
            {
                //find what it contains. used the findElements method to avoid the NoSuchElementException
                //so lists should always be a size of one or empty.
                List<WebElement> buttons = thirdTd.get(0).findElements(By.cssSelector("button"));
                
                if (buttons.size() > 0)
                {
                    assertThat(buttons.get(0).getText(), is("Delete"));
                    buttons.get(0).click();
                    break;
                }
            }
        }
        
        //Fluent wait needed because it may take a second for the table to be updated when a parameter is removed.
        fwait.until(new ExpectedCondition<Boolean>()
        {
            @Override
            public Boolean apply(WebDriver driver)
            {
                List<WebElement> tableRows = getParameterTableRows(AssetCommandHelper.
                        getAssetCommandPanel(m_Driver, ASSET_NAME));
                return tableRows.size() == rowCount;
            }
        });
        
        AssetCommandHelper.clickAccordionPanel(m_Driver, ASSET_NAME, "Capture Image", ExpandCollapse.COLLAPSE);
    }
/*
     * Verify that you can hit add/delete button and the parameter table updates accordingly.
     */
Verify that you can hit add/delete button and the parameter table updates accordingly.
Verify that you can hit add / delete button and the parameter table updates accordingly .
@Test
    public void testAddDeleteParameterButton() throws InterruptedException, ExecutionException, TimeoutException
    {
        AssetCommandHelper.clickAccordionPanel(m_Driver, ASSET_NAME, "Capture Image", ExpandCollapse.EXPAND);
        List<WebElement> tableRows = getParameterTableRows(AssetCommandHelper.
                getAssetCommandPanel(m_Driver, ASSET_NAME));
        final int rowCount = tableRows.size();
        for (WebElement row : tableRows)
        {
            List<WebElement> thirdTd = row.findElements(By.cssSelector("td:nth-child(3)"));
            if (thirdTd.size() > 0)
            {
                List<WebElement> buttons = thirdTd.get(0).findElements(By.cssSelector("button"));
                if (buttons.size() > 0)
                {
                    assertThat(buttons.get(0).getText(), is("Add"));
                    buttons.get(0).click();
                    break;
                }
            }
        }
        Wait<WebDriver> fwait = new FluentWait<WebDriver>(m_Driver).withTimeout(30, TimeUnit.SECONDS).
                pollingEvery(1, TimeUnit.SECONDS).ignoring(StaleElementReferenceException.class, 
                        NoSuchElementException.class);
        fwait.until(new ExpectedCondition<Boolean>()
        {
            @Override
            public Boolean apply(WebDriver driver)
            {
                List<WebElement> tableRows = getParameterTableRows(AssetCommandHelper.
                        getAssetCommandPanel(m_Driver, ASSET_NAME));
                return tableRows.size() > rowCount;
            }
        });
        tableRows = getParameterTableRows(AssetCommandHelper.
                getAssetCommandPanel(m_Driver, ASSET_NAME));
        for (WebElement row : tableRows)
        {
            List<WebElement> thirdTd = row.findElements(By.cssSelector("td:nth-child(3)"));
            if (thirdTd.size() > 0)
            {
                List<WebElement> buttons = thirdTd.get(0).findElements(By.cssSelector("button"));
                if (buttons.size() > 0)
                {
                    assertThat(buttons.get(0).getText(), is("Delete"));
                    buttons.get(0).click();
                    break;
                }
            }
        }
        fwait.until(new ExpectedCondition<Boolean>()
        {
            @Override
            public Boolean apply(WebDriver driver)
            {
                List<WebElement> tableRows = getParameterTableRows(AssetCommandHelper.
                        getAssetCommandPanel(m_Driver, ASSET_NAME));
                return tableRows.size() == rowCount;
            }
        });
        AssetCommandHelper.clickAccordionPanel(m_Driver, ASSET_NAME, "Capture Image", ExpandCollapse.COLLAPSE);
    }
@ Test public void testAddDeleteParameterButton ( ) throws InterruptedException , ExecutionException , TimeoutException { AssetCommandHelper . clickAccordionPanel ( m_Driver , ASSET_NAME , "Capture Image" , ExpandCollapse . EXPAND ) ; List < WebElement > tableRows = getParameterTableRows ( AssetCommandHelper . getAssetCommandPanel ( m_Driver , ASSET_NAME ) ) ; final int rowCount = tableRows . size ( ) ; for ( WebElement row : tableRows ) { List < WebElement > thirdTd = row . findElements ( By . cssSelector ( "td:nth-child(3)" ) ) ; if ( thirdTd . size ( ) > 0 ) { List < WebElement > buttons = thirdTd . get ( 0 ) . findElements ( By . cssSelector ( "button" ) ) ; if ( buttons . size ( ) > 0 ) { assertThat ( buttons . get ( 0 ) . getText ( ) , is ( "Add" ) ) ; buttons . get ( 0 ) . click ( ) ; break ; } } } Wait < WebDriver > fwait = new FluentWait < WebDriver > ( m_Driver ) . withTimeout ( 30 , TimeUnit . SECONDS ) . pollingEvery ( 1 , TimeUnit . SECONDS ) . ignoring ( StaleElementReferenceException . class , NoSuchElementException . class ) ; fwait . until ( new ExpectedCondition < Boolean > ( ) { @ Override public Boolean apply ( WebDriver driver ) { List < WebElement > tableRows = getParameterTableRows ( AssetCommandHelper . getAssetCommandPanel ( m_Driver , ASSET_NAME ) ) ; return tableRows . size ( ) > rowCount ; } } ) ; tableRows = getParameterTableRows ( AssetCommandHelper . getAssetCommandPanel ( m_Driver , ASSET_NAME ) ) ; for ( WebElement row : tableRows ) { List < WebElement > thirdTd = row . findElements ( By . cssSelector ( "td:nth-child(3)" ) ) ; if ( thirdTd . size ( ) > 0 ) { List < WebElement > buttons = thirdTd . get ( 0 ) . findElements ( By . cssSelector ( "button" ) ) ; if ( buttons . size ( ) > 0 ) { assertThat ( buttons . get ( 0 ) . getText ( ) , is ( "Delete" ) ) ; buttons . get ( 0 ) . click ( ) ; break ; } } } fwait . until ( new ExpectedCondition < Boolean > ( ) { @ Override public Boolean apply ( WebDriver driver ) { List < WebElement > tableRows = getParameterTableRows ( AssetCommandHelper . getAssetCommandPanel ( m_Driver , ASSET_NAME ) ) ; return tableRows . size ( ) == rowCount ; } } ) ; AssetCommandHelper . clickAccordionPanel ( m_Driver , ASSET_NAME , "Capture Image" , ExpandCollapse . COLLAPSE ) ; }
Verify that you can hit add/delete button and the parameter table updates accordingly.
Verify that you can hit add / delete button and the parameter table updates accordingly .
//find an add button //find what it contains. used the findElements method to avoid the NoSuchElementException //so lists should always be a size of one or empty. //Fluent wait used to wait for the parameter table to be updated when adding or deleting a parameter. //Fluent wait needed because it may take a second for the table to be updated when a parameter is removed. //find the delete button that was the add button //find what it contains. used the findElements method to avoid the NoSuchElementException //so lists should always be a size of one or empty. //Fluent wait needed because it may take a second for the table to be updated when a parameter is removed.