PMC:QA:Sahi junit test for Adempiere SO order
From ADempiere
This Wiki is read-only for reference purposes to avoid broken links.
Sahi junit test for AD SO order
AdSOOrderTest.java
package in.co.sahi; import junit.framework.TestCase; import net.sf.sahi.client.Browser; import net.sf.sahi.client.ExecutionException; import net.sf.sahi.config.Configuration; /** * * This is a sample class to get started with Sahi Java.<br/> * Have a look at DriverClientTest.java in sample_java_project dir for more detailed use of APIs.<br/> * You need sahi/lib/sahi.jar in your classpath.</br> * */ public class AdSOOrderTest extends TestCase { private Browser browser; private String sahiBase; private String userDataDirectory; /** * This starts the Sahi proxy, toggles the proxy settings on Internet Explorer * and starts a browser instance. This could be part of your setUp method in a JUnit test. * */ public void setUp(){ sahiBase = "/mnt/sda4/Sahi/sahi0321/sahi/"; // where Sahi is installed or unzipped userDataDirectory = "/mnt/sda4/Sahi/sahi0321/sahi/sample_java_project/myuserdata/"; Configuration.initJava(sahiBase, userDataDirectory); // Sets up configuration for proxy. Sets Controller to java mode. String browserPath = "/usr/bin/firefox"; String browserProcessName = "firefox"; String browserOption = "-profile /mnt/sda4/Sahi/sahi0321/sahi/userdata/browser/ff/profiles/sahi1 -no-remote"; browser = new Browser(browserPath, browserProcessName, browserOption); browser.open(); } public void testSoorder() throws ExecutionException{ browser.navigateTo("http://adresearch.xiancaro.com/webui/"); browser.setValue(browser.textbox(0), "SuperUser"); assertEquals("SuperUser", browser.textbox(0).value()); browser.setValue(browser.password(0), "System"); assertTrue(browser.image(1).exists()); browser.click(browser.image(1)); browser.click(browser.cell("English")); browser.click(browser.image(2)); browser.click(browser.image("spacer.gif")); browser.click(browser.cell("GardenWorld Admin")); browser.click(browser.image("spacer.gif[1]")); System.out.println("check:ok button browser.image(5).exists() = "+ browser.image(5).exists()); browser.click(browser.image(5)); browser.waitFor(1000); browser.navigateTo("http://adresearch.xiancaro.com/webui/"); browser.click(browser.span("z-tree-ico z-tree-root-close[3]")); browser.click(browser.span("z-tree-ico z-tree-tee-close[18]")); browser.click(browser.image("mWindow.png[145]")); browser.click(browser.image("New24.png")); browser.click(browser.image("spacer.gif[2]")); browser.click(browser.cell("HQ")); browser.click(browser.image("spacer.gif[3]")); browser.click(browser.cell("POS Order")); browser.setValue(browser.textbox(9), "Joe Block"); browser.click(browser.image("spacer.gif[14]")); browser.click(browser.cell("HQ Warehouse")); browser.click(browser.image("spacer.gif[23]")); browser.click(browser.cell("Standard[1]")); browser.click(browser.image("spacer.gif[26]")); browser.click(browser.cell("GardenAdmin")); browser.click(browser.image("Save24.png")); browser.click(browser.submit("Order Line")); browser.click(browser.image("Product10.png")); browser.click(browser.image("Refresh24.png[1]")); browser.click(browser.div("Mary Consultant")); browser.click(browser.image("Ok24.png")); browser.click(browser.image("spacer.gif[51]")); browser.click(browser.cell("Standard[3]")); browser.click(browser.image("Save24.png")); browser.click(browser.submit("Order")); browser.click(browser.cell("Complete[1]")); browser.waitFor(1000); //browser.setValue(browser.select(0), "Complete"); browser.click(browser.image("Ok24.png")); browser.waitFor(180000); assertEquals("Completed",browser.textbox(47).value()); System.out.println("check:Document Status = "+ browser.textbox(47).value()); if(browser.textbox(47).value().equals("Completed")){ System.out.println("sales order is completed!!!"); }else{ System.out.println("sales order is not completed!!!"); } browser.click(browser.link(4)); browser.click(browser.link("Log Out")); } /** * This closes the browser instance, stops the proxy and toggles back the IE proxy settings. * This could be part of your JUnit tearDown. */ public void tearDown(){ browser.close(); // proxy.stop(); // toggleIEProxy(false); // Not needed for Firefox. Needed for IE, Safari, Chrome on Windows } }
test result:
junit test codes in the above class
assertEquals("SuperUser", browser.textbox(0).value()); assertTrue(browser.image(1).exists()); System.out.println("check:ok button browser.image(5).exists() = "+ browser.image(5).exists()); assertEquals("Completed",browser.textbox(47).value()); System.out.println("check:Document Status = "+ browser.textbox(47).value()); if(browser.textbox(47).value().equals("Completed")){ System.out.println("sales order is completed!!!"); }else{ System.out.println("sales order is not completed!!!"); }
we can add more assertions.
codes that confirm the order is completed or not.
assertEquals("Completed",browser.textbox(47).value()); System.out.println("check:Document Status = "+ browser.textbox(47).value()); if(browser.textbox(47).value().equals("Completed")){ System.out.println("sales order is completed!!!"); }else{ System.out.println("sales order is not completed!!!"); }
Links
Go back to PMC:QA