mercredi 25 mars 2020

conditional constructs in Java automated testing

I'm trying to automate a chat-bot test. During the automated conversation, the bot should appear to go out of the tabs to be selected, but this does not always happen! So I should write a condition to handle the exception. I tried using the if-else construct, but the test fails! could someone help me?

    if(driver.findElement(By.xpath("//*[@id=\"BotChatGoesHere\"]/div/div/div[4]/div/div/div[11]/div/div[3]/div/div/div[2]/div/div/div/ul")).isDisplayed()){

            WebElement send3=driver.findElement(By.xpath("//*[@id=\"BotChatGoesHere\"]/div/div/div[4]/div/div/div[11]/div/div[3]/div/div/div[2]/div/div/div/ul/li[3]/div/div[1]"));
            send3.click();

            wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"BotChatGoesHere\"]/div/div/div[4]/div/div/div[14]/div/div/div/ul")));

            WebElement inputText4=driver.findElement(By.xpath("//*[@id=\"inputUsername\"]"));
            inputText4.sendKeys("xxx@gmail.com");
            WebElement send4=driver.findElement(By.xpath("//*//*[@id=\"BotChatGoesHere\"]/div/div/div[5]/label[2]"));
            send4.click();

            wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"BotChatGoesHere\"]/div/div/div[4]/div/div/div[15]/div/div[3]/div/div/div")));

            WebElement inputText5=driver.findElement(By.xpath("//*[@id=\"inputPassword\"]"));
            inputText5.sendKeys("xxx");

            WebElement send5=driver.findElement(By.xpath("//*//*[@id=\"BotChatGoesHere\"]/div/div/div[5]/label[2]"));
            send5.click();
        }
        else{
            wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"BotChatGoesHere\"]/div/div/div[4]/div/div/div[10]/div/div/div/ul")));

            WebElement send3=driver.findElement(By.xpath("//*[@id=\"BotChatGoesHere\"]/div/div/div[4]/div/div/div[10]/div/div/div/ul/li[2]/button"));
            send3.click();

            wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"BotChatGoesHere\"]/div/div/div[4]/div/div/div[12]/div/div[3]/div/div/div[2]/div/div/div/ul")));

            WebElement sendmiao=driver.findElement(By.xpath("//*[@id=\"BotChatGoesHere\"]/div/div/div[4]/div/div/div[12]/div/div[3]/div/div/div[2]/div/div/div/ul/li[3]/div/div[1]"));
            sendmiao.click();

            wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"BotChatGoesHere\"]/div/div/div[4]/div/div/div[14]/div/div[3]/div/div/div")));

            WebElement inputText4=driver.findElement(By.xpath("//*[@id=\"inputUsername\"]"));
            inputText4.sendKeys("xxx@gmail.com");
            WebElement send4=driver.findElement(By.xpath("//*//*[@id=\"BotChatGoesHere\"]/div/div/div[5]/label[2]"));
            send4.click();

            wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"BotChatGoesHere\"]/div/div/div[4]/div/div/div[16]/div/div[3]/div/div/div")));

            WebElement inputText5=driver.findElement(By.xpath("//*[@id=\"inputPassword\"]"));
            inputText5.sendKeys("xxx");

            WebElement send5=driver.findElement(By.xpath("//*//*[@id=\"BotChatGoesHere\"]/div/div/div[5]/label[2]"));
            send5.click();
        }

Aucun commentaire:

Enregistrer un commentaire