package com.sdl.weblocator.extjs;

import com.extjs.selenium.button.Button;
import com.extjs.selenium.conditions.MessageBoxFailCondition;
import com.extjs.selenium.conditions.MessageBoxSuccessCondition;
import com.extjs.selenium.panel.Panel;
import com.extjs.selenium.window.MessageBox;
import com.extjs.selenium.window.Window;
import com.sdl.selenium.conditions.ConditionManager;
import com.sdl.weblocator.TestBase;
import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Test;

public class ConditionManagerTest extends TestBase {
    private static final Logger logger = Logger.getLogger(ConditionManagerTest.class);
    Panel conditionManagerPanel = new Panel("Condition Manager");
    Button expect1Button = new Button(conditionManagerPanel, "Expect1");
    Button expect2Button = new Button(conditionManagerPanel, "Expect2");
    Button expect3Button = new Button(conditionManagerPanel, "Expect3");

    private Window messageBoxWindow = new Window(true).setClasses("x-window-dlg").setInfoMessage("MessageBox");
    Button button = new Button(messageBoxWindow, "Nossss");

    @Test
    public void conditionManagerTest() {
        expect1Button.click();
        ConditionManager conditionManager = new ConditionManager(10000);
        conditionManager.add(new MessageBoxSuccessCondition("Expect1 button was pressed"));
        conditionManager.add(new MessageBoxFailCondition("Expect2 button was pressed"));
        conditionManager.add(new MessageBoxFailCondition("Expect3 button was pressed"));
        Assert.assertTrue(conditionManager.execute().isSuccess());
        MessageBox.pressOK();

    }

    @Test
    public void conditionManagerTest1() {
        expect2Button.click();
        ConditionManager conditionManager = new ConditionManager(10000);
        conditionManager.add(new MessageBoxSuccessCondition("Expect2 button was pressed"));
        conditionManager.add(new MessageBoxFailCondition("Expect1 button was pressed"));
        conditionManager.add(new MessageBoxFailCondition("Expect3 button was pressed"));
        Assert.assertTrue(conditionManager.execute().isSuccess());
        MessageBox.pressOK();

    }

    @Test
    public void conditionManagerTest2() {
        expect3Button.click();
        ConditionManager conditionManager = new ConditionManager(10000);
        conditionManager.add(new MessageBoxSuccessCondition("Are you sure you want to do that?"));
        conditionManager.add(new MessageBoxFailCondition("Expect2 button was pressed"));
        conditionManager.add(new MessageBoxFailCondition("Expect1 button was pressed"));
        Assert.assertTrue(conditionManager.execute().isSuccess()); //&& new MessageBox("Are you sure you want to do that?").pressYES());
        MessageBox.pressYes();

    }

    /*@Test
    public void conditionManagerContainsMessage() {
        showYesAlert.click();

        ConditionManager conditionManager = new ConditionManager(10000);
        conditionManager.add(new MessageBoxSuccessCondition("Would you like to save your changes?", true));
        String msg = "";
        if(conditionManager.execute().isSuccess()){
            msg = MessageBox.pressYes();
        }
        Assert.assertEquals(msg, "You are closing a tab that has unsaved changes.\n" +
                "Would you like to save your changes?");
    }

    @Test
    public void messageBoxTest() {
        showAlert.click();
        MessageBox.pressOK();
        //Assert.assertTrue(new MessageBox("Changes saved successfully.").pressOk());
        showAlert.click();
        Assert.assertEquals(MessageBox.pressOK(), "Changes saved successfully.");
    }*/
}

@@ -321,16 +321,62 @@
 Window;%0A
+import com.sdl.selenium.conditions.Condition;%0A
 import c
@@ -416,24 +416,24 @@
 ionManager;%0A
-
 import com.s
@@ -1158,53 +1158,48 @@
     
-@Test%0A    public void conditionManagerTest() 
+private Condition doClick(Button button)
 %7B%0A  
@@ -1204,24 +1204,17 @@
         
-expect1B
+b
 utton.cl
@@ -1212,32 +1212,33 @@
 button.click();%0A
+%0A
         Conditio
@@ -1560,32 +1560,33 @@
 pressed%22));%0A
+%0A
         
 Assert.asser
@@ -1577,52 +1577,329 @@
     
-Assert.assertTrue(conditionManager.
+Condition condition = conditionManager.execute();%0A        return condition;%0A    %7D%0A%0A    @Test%0A    public void conditionManagerTest() %7B%0A        Condition condition = doClick(
 ex
+p
 ec
-ute()
+t1Button);%0A%0A        if(condition.isFail())%7B%0A            logger.warn(condition.getResultMessage());%0A        %7D%0A        Assert.assertTrue(condition
 .isS
@@ -1901,32 +1901,33 @@
 n.isSuccess());%0A
+%0A
         MessageB
@@ -1932,33 +1932,32 @@
 eBox.pressOK();%0A
-%0A
     %7D%0A%0A    @Test

improve Code example for ConditionManagerTest