Ignore:
Timestamp:
01/19/11 14:25:51 (13 years ago)
Author:
luiz-fernando
Message:

Ticket #1402 - Novos casos de teste implementados usando WebDriver?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/testlink/automation2.0/src/test/java/br/gov/serpro/expresso/cte/pages/email/MailPage.java

    r3663 r3708  
    22 
    33import org.apache.commons.lang.StringUtils; 
     4import org.openqa.selenium.Alert; 
     5import org.openqa.selenium.By; 
    46import org.openqa.selenium.JavascriptExecutor; 
     7import org.openqa.selenium.RenderedWebElement; 
    58import org.openqa.selenium.WebDriver; 
    69import org.openqa.selenium.WebElement; 
     
    3033 
    3134        @FindBy(id = "important_message_1") 
     35        /** Flag de importante no momento de compor um email. */ 
    3236        private WebElement important; 
     37 
     38        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]") 
     39        /** Flag de importante de um email aberto. */ 
     40        private WebElement importantFlag; 
     41 
     42        @FindBy(id = "span_flag_FLAGGED") 
     43        /** Filtra emails importantes. */ 
     44        private WebElement importantFilter; 
     45 
     46        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]") 
     47        private WebElement normalFlag; 
     48 
     49        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[2]") 
     50        private WebElement notReadFlag; 
    3351 
    3452        @FindBy(id = "return_receipt_1") 
     
    5068        private WebElement saveEmail; 
    5169 
    52         @FindBy(xpath = "//div[@id='div_message_scroll_1']/form/table/tbody/tr[10]/td[2]/a") 
     70        @FindBy(linkText = "Anexos: adicionar+") 
    5371        private WebElement attachmentLink; 
    5472 
     
    5674        private WebElement attachment; 
    5775 
     76        @FindBy(id = "inputFile_1_2") 
     77        private WebElement attachment2; 
     78 
    5879        @FindBy(xpath = "//div[@id='footer_menu']/table[@id='footer_box']/tbody/tr[@id='table_message']/td[@id='span_options']/span[1]/span") 
    5980        private WebElement deleteEmailLink; 
     
    7192        private WebElement totalEmails; 
    7293 
     94        @FindBy(xpath = "//div[@id='exmail_main_body']/table[1]/tbody[@id='border_tbody']/tr[1]/td[2]/table/tbody/tr/td[1]") 
     95        private WebElement emailTab; 
     96 
     97        @FindBy(id = "chk_box_select_all_messages") 
     98        private WebElement selectAllEmails; 
     99 
     100        @FindBy(xpath = "//td[@id='link_tools']/div/span") 
     101        private WebElement toolsMenu; 
     102 
     103        @FindBy(xpath = "//div[@id='menu_tools']/table/tbody/tr[4]/td") 
     104        private WebElement editFolder; 
     105 
     106        @FindBy(xpath = "//input[@value='Nova Pasta']") 
     107        private WebElement createNewFolder; 
     108 
     109        @FindBy(xpath = "//input[@value='Excluir pasta']") 
     110        private WebElement deleteFolder; 
     111 
     112        @FindBy(xpath = "//span[@onclick='wfolders.makeWindow(\"\",\"move_to\")']") 
     113        /** Opcao de mover do rodape. */ 
     114        private WebElement moveEmailLink; 
     115 
     116        @FindBy(id = "dJSWin_wfolders_bok") 
     117        private WebElement moveEmailButton; 
     118 
     119        @FindBy(xpath = "//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[3]") 
     120        private WebElement forwardEmail; 
     121 
    73122        /** 
    74123         * @param driver 
     
    78127        } 
    79128 
    80         /** 
    81          * @param to 
    82          * @param subject 
    83          * @param body 
    84          */ 
    85         public void composeEmail(String to, String subject, String body) { 
     129        public void createNewEmail() { 
    86130                this.newEmail.click(); 
    87131                waitForElementById("to_1"); 
    88                 this.to.sendKeys(to); 
     132        } 
     133 
     134        public void setSubject(String subject) { 
    89135                this.subject.sendKeys(subject != null ? subject : ""); 
    90  
     136        } 
     137 
     138        public void setBody(String body) { 
    91139                // Foi o unico jeito que consegui pegar o richtexteditor... 
    92140                if (body != null) { 
     
    98146 
    99147        /** 
     148         * @param to 
     149         * @param subject 
     150         * @param body 
     151         */ 
     152        public void composeEmail(String to, String subject, String body) { 
     153                this.createNewEmail(); 
     154                this.to.sendKeys(to); 
     155                this.setSubject(subject); 
     156                this.setBody(body); 
     157        } 
     158 
     159        public String readEmail(String subject) { 
     160                String id = findEmailIdBySuject(subject); 
     161                clickElement(id); 
     162                return id.substring(id.lastIndexOf("_") + 1); 
     163                // waitForElementByXpath("//div[@id='exmail_main_body']/table[1]/tbody[@id='border_tbody']/tr[1]/td[2]/table/tbody/tr/td[1]"); 
     164        } 
     165 
     166        /** 
     167         * Encaminha uma mensagem. 
     168         *  
     169         * @param id 
     170         *            Id da mensagem a ser encaminhada 
     171         * @param to 
     172         *            Destinatario 
     173         */ 
     174        public void forwardEmail(String id, String to) { 
     175                super.waitForElementByXpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[3]/span[3]"); 
     176                this.forwardEmail.click(); 
     177                super.waitForElementById("to_" + id); 
     178                driver.findElement(By.id("to_" + id)).sendKeys(to); 
     179                driver.findElement(By.id("send_button_" + id)).click(); 
     180        } 
     181 
     182        /** 
    100183         * Abre uma pasta de email especifica. 
    101184         *  
     
    119202        } 
    120203 
     204        public void setImportantFilter() { 
     205                this.importantFilter.click(); 
     206        } 
     207 
    121208        /** 
    122209         * Limpa a lixeira. 
     
    134221        } 
    135222 
     223        public void moveEmail(String folderName) { 
     224                this.moveEmailLink.click(); 
     225                super.findAndClickElement("lINBOX/" + folderName + "wfolders_tree"); 
     226                this.moveEmailButton.click(); 
     227        } 
     228 
     229        public void editFolder() { 
     230                this.toolsMenu.click(); 
     231                this.waitForElementByXpath("//div[@id='menu_tools']/table/tbody/tr[4]/td"); 
     232                this.editFolder.click(); 
     233        } 
     234 
     235        public void createNewFolder(String folderName) { 
     236                this.editFolder(); 
     237                this.createNewFolder.click(); 
     238                Alert newFolder = driver.switchTo().alert(); 
     239                assert "Insira o nome da nova pasta: ".equals(newFolder.getText()); 
     240                newFolder.sendKeys(folderName); 
     241                newFolder.accept(); 
     242        } 
     243 
     244        public void deleteFolder(String folderName) { 
     245                this.editFolder(); 
     246                this.driver.findElement(By.id("lINBOX/" + folderName + "folders_tree")) 
     247                                .click(); 
     248                this.deleteFolder.click(); 
     249                Alert confirm = driver.switchTo().alert(); 
     250                assert ("Você gostaria de excluir a pasta: " + folderName + "?") 
     251                                .equals(confirm.getText()); 
     252                confirm.accept(); 
     253        } 
     254 
    136255        /** 
    137256         * Marca email sendo composto como importante. 
    138257         */ 
     258        public void checkImportantFlag() { 
     259                this.important.click(); 
     260        } 
     261 
    139262        public void setImportantFlag() { 
    140                 this.important.click(); 
     263                this.waitForElementByXpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]"); 
     264                this.importantFlag.click(); 
     265        } 
     266 
     267        public void setNormalFlag() { 
     268                this.waitForElementByXpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[3]"); 
     269                this.normalFlag.click(); 
     270        } 
     271 
     272        public void setNotReadFlag() { 
     273                this.waitForElementByXpath("//div[@id='exmail_main_body']/div[2]/table/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/span[2]"); 
     274                this.notReadFlag.click(); 
    141275        } 
    142276 
     
    144278         * Marca solicitacao de confirmacao de leitura do email sendo composto. 
    145279         */ 
    146         public void setReturnReceipt() { 
     280        public void checkReturnReceipt() { 
    147281                this.returnReceipt.click(); 
    148282        } 
     
    163297        public void deleteEmail() { 
    164298                this.deleteEmailLink.click(); 
     299        } 
     300 
     301        public void selectAllEmails() { 
     302                this.selectAllEmails.click(); 
    165303        } 
    166304 
     
    196334                this.attachmentLink.click(); 
    197335                this.attachment.sendKeys(attachment); 
     336        } 
     337 
     338        public void addAttachment2(String attachment) { 
     339                this.attachmentLink.click(); 
     340                this.attachment2.sendKeys(attachment); 
    198341        } 
    199342 
     
    244387 
    245388        /** 
     389         * @return Ids de todos os emails da pasta selecionada. 
     390         */ 
     391        public String[] getEmailIds() { 
     392                String[] ids = new String[this.getTotalEmails()]; 
     393                for (int i = 1; i <= this.getTotalEmails(); i++) { 
     394                        String id = driver 
     395                                        .findElement( 
     396                                                        By.xpath("//div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[" 
     397                                                                        + i + "]/td[1]/input[1]")).getAttribute( 
     398                                                        "id"); 
     399                        ids[i - 1] = id.substring(id.lastIndexOf("_") + 1); 
     400                } 
     401                return ids; 
     402        } 
     403 
     404        /** 
     405         * @param emailId 
     406         *            Id do email. 
     407         * @return <code>true</code> se email importante, <code>false</code> caso 
     408         *         contrario. 
     409         */ 
     410        public boolean isImportant(String emailId) { 
     411                return super 
     412                                .isDisplayed((RenderedWebElement) driver.findElement(By 
     413                                                .xpath("//div[@id='exmail_main_body']/div[@id='content_id_0']/div[@id='divScrollMain_0']/table[@id='table_box']/tbody[@id='tbody_box']/tr[@id='" 
     414                                                                + emailId + "']/td[5]/img"))); 
     415        } 
     416 
     417        public String findEmailIdBySuject(String subject) { 
     418                return findEmailIdBySuject(subject, false); 
     419        } 
     420 
     421        /** 
    246422         * Verifica se mensagem informada corresponde ao exibido pelo Expresso na 
    247423         * div onde sao exibidas mensagens ao usuario. 
Note: See TracChangeset for help on using the changeset viewer.