/reference-projects/benchmarks/src/test/groovy/org/telluriumsource/test/JettyLogonTestNGTestCase.java

http://aost.googlecode.com/ · Java · 130 lines · 97 code · 15 blank · 18 comment · 0 complexity · 93211bf43dd917e0bcf4a78c99dcf53a MD5 · raw file

  1. package org.telluriumsource.test;
  2. import org.telluriumsource.module.JettyLogonModule;
  3. import org.telluriumsource.test.java.TelluriumTestNGTestCase;
  4. import org.telluriumsource.test.mock.MockHttpServer;
  5. import org.testng.annotations.*;
  6. /**
  7. * @author Jian Fang (John.Jian.Fang@gmail.com)
  8. *
  9. * Date: Jan 3, 2010
  10. *
  11. */
  12. public class JettyLogonTestNGTestCase extends TelluriumTestNGTestCase {
  13. private static JettyLogonModule jlm;
  14. private static MockHttpServer server;
  15. @BeforeClass
  16. public static void initUi() {
  17. server = new MockHttpServer(8080);
  18. server.registerHtmlBody("/logon.html", JettyLogonModule.HTML_BODY);
  19. server.start();
  20. jlm = new JettyLogonModule();
  21. jlm.defineUi();
  22. connectSeleniumServer();
  23. useTelluriumEngine(true);
  24. useTrace(true);
  25. }
  26. @DataProvider(name = "config-provider")
  27. public Object[][] configParameters() {
  28. // boolean useSelector, boolean useCache, boolean useTeApi
  29. return new Object[][]{
  30. new Object[]{true, true, true},
  31. new Object[]{true, true, false},
  32. new Object[]{true, false, true},
  33. new Object[]{true, false, false},
  34. new Object[]{false, true, true},
  35. new Object[]{false, true, false},
  36. new Object[]{false, false, true},
  37. new Object[]{false, false, false}
  38. };
  39. }
  40. @DataProvider(name = "good-provider")
  41. public Object[][] configGoodParameters() {
  42. //boolean useSelector, boolean useCache, boolean useTeApi
  43. return new Object[][]{
  44. new Object[]{true, true, true},
  45. new Object[]{true, true, false},
  46. new Object[]{false, true, true},
  47. new Object[]{false, true, false},
  48. };
  49. }
  50. @DataProvider(name = "bad-provider")
  51. public Object[][] configBadParameters() {
  52. //boolean useSelector, boolean useCache, boolean useTeApi
  53. return new Object[][]{
  54. new Object[]{true, false, true},
  55. new Object[]{true, false, false},
  56. new Object[]{false, false, true},
  57. new Object[]{false, false, false}
  58. };
  59. }
  60. @BeforeMethod
  61. public void connectToLocal() {
  62. connectUrl("http://localhost:8080/logon.html");
  63. }
  64. @Test
  65. public void testStringifyUiModule(){
  66. String json = jlm.toString("Form");
  67. System.out.println(json);
  68. }
  69. @Test
  70. public void testDiagnose(){
  71. jlm.diagnose("Form.Username.Input");
  72. jlm.diagnose("ProblematicForm.Username.Input");
  73. }
  74. @Test
  75. public void testValidateUiModule(){
  76. jlm.validate("Form");
  77. jlm.validate("ProblematicForm");
  78. }
  79. @Test(dataProvider = "config-provider")
  80. @Parameters({"useSelector", "useCache", "useTeApi"})
  81. public void testLogon(boolean useSelector, boolean useCache, boolean useTeApi) {
  82. useCssSelector(useSelector);
  83. // useCache(useCache);
  84. // useTelluriumApi(useTeApi);
  85. jlm.logon("test", "test");
  86. }
  87. //When UI Module cacheing is on, we can use closest match to find the UI module even though its definition may
  88. // not be incorrect to some degree
  89. @Test(dataProvider = "good-provider")
  90. @Parameters({"useSelector", "useCache", "useTeApi"})
  91. public void testGoodLogonWithClosestMatch(boolean useSelector, boolean useCache, boolean useTeApi) {
  92. useClosestMatch(true);
  93. useCssSelector(useSelector);
  94. // useCache(useCache);
  95. // useTelluriumApi(useTeApi);
  96. jlm.plogon("test", "test");
  97. useClosestMatch(false);
  98. }
  99. //If the Ui Module cache is off, cannot locate the not-so-accurate UI element
  100. @Test(dataProvider = "bad-provider", expectedExceptions = com.thoughtworks.selenium.SeleniumException.class)
  101. @Parameters({"useSelector", "useCache", "useTeApi"})
  102. public void testBadLogonWithClosestMatch(boolean useSelector, boolean useCache, boolean useTeApi) {
  103. useClosestMatch(true);
  104. useCssSelector(useSelector);
  105. // useCache(useCache);
  106. // useTelluriumApi(useTeApi);
  107. jlm.plogon("test", "test");
  108. useClosestMatch(false);
  109. }
  110. @AfterClass
  111. public static void tearDown(){
  112. showTrace();
  113. server.stop();
  114. }
  115. }