Guest User

Untitled

a guest
Oct 1st, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.90 KB | None | 0 0
  1. package common;
  2.  
  3. /**
  4. *
  5. * @author Aruns
  6. */
  7. public class common extends config {
  8.  
  9. public common() {
  10.  
  11. }
  12.  
  13. }
  14.  
  15. package common;
  16.  
  17. /**
  18. *
  19. * @author Aruns
  20. */
  21. public class config {
  22.  
  23. private final String base_url = "http://localhost/hospitalnew";
  24. private int timeout = 10;
  25. private String browser = "chrome";
  26. private final String chromeDriver = "C:\xampp\htdocs\driver\driver\chromedriver.exe";
  27. private final String geckoDriver = "C:\xampp\htdocs\driver\driver\firefoxdriver.exe";
  28. private final String ieDriver = "C:\xampp\htdocs\driver\driver\operadriver.exe";
  29. private String currentUrl = "";
  30. private String currentTitle = "";
  31. private String username = "arun-reception";
  32. private String password = "arun";
  33.  
  34. public String getUsername() {
  35. return username;
  36. }
  37.  
  38. public void setUsername(String username) {
  39. this.username = username;
  40. }
  41.  
  42. public String getPassword() {
  43. return password;
  44. }
  45.  
  46. public void setPassword(String password) {
  47. this.password = password;
  48. }
  49.  
  50. public String getCurrentUrl() {
  51. return currentUrl;
  52. }
  53.  
  54. public void setCurrentUrl(String currentUrl) {
  55. this.currentUrl = currentUrl;
  56. }
  57.  
  58. public String getCurrentTitle() {
  59. return currentTitle;
  60. }
  61.  
  62. /**
  63. * sets current Title
  64. *
  65. * @param currentTitle = url
  66. */
  67. public void setCurrentTitle(String currentTitle) {
  68. this.currentTitle = currentTitle;
  69. }
  70.  
  71. public String getChromeDriver() {
  72. return chromeDriver;
  73. }
  74.  
  75. public String getGeckoDriver() {
  76. return geckoDriver;
  77. }
  78.  
  79. public String getIeDriver() {
  80. return ieDriver;
  81. }
  82.  
  83. public String getBrowser() {
  84. return browser;
  85. }
  86.  
  87. public void setBrowser(String browser) {
  88. this.browser = browser;
  89. }
  90.  
  91. public String getBase_url() {
  92. return base_url;
  93. }
  94.  
  95. public int getTimeout() {
  96. return timeout;
  97. }
  98.  
  99. public void setTimeout(int timeout) {
  100. this.timeout = timeout;
  101. }
  102.  
  103. }
  104.  
  105. package critical;
  106.  
  107. import common.common;
  108. import java.util.concurrent.TimeUnit;
  109. import org.openqa.selenium.By;
  110. import org.openqa.selenium.WebDriver;
  111. import org.openqa.selenium.WebElement;
  112. import org.openqa.selenium.chrome.ChromeDriver;
  113. import static org.testng.Assert.*;
  114. import org.testng.annotations.AfterClass;
  115. import org.testng.annotations.AfterMethod;
  116. import org.testng.annotations.BeforeClass;
  117. import org.testng.annotations.BeforeMethod;
  118. import org.testng.annotations.Test;
  119.  
  120. /**
  121. *
  122. * @author Aruns
  123. */
  124. public class TestNavigationMenu {
  125.  
  126. public TestNavigationMenu() {
  127. }
  128.  
  129. // TODO add test methods here.
  130. // The methods must be annotated with annotation @Test. For example:
  131. //
  132. // @Test
  133. // public void hello() {}
  134. WebDriver driver;
  135. common common;
  136. WebElement element;
  137.  
  138. @BeforeClass
  139. public static void setUpClass() throws Exception {
  140. }
  141.  
  142. @AfterClass
  143. public static void tearDownClass() throws Exception {
  144. }
  145.  
  146. @BeforeMethod
  147. public void setUpMethod() throws Exception {
  148. common = new common();
  149. System.setProperty("webdriver.chrome.driver", common.getChromeDriver());
  150. driver = new ChromeDriver();
  151. driver.manage().timeouts().implicitlyWait(common.getTimeout(), TimeUnit.SECONDS);
  152. }
  153.  
  154. @AfterMethod
  155. public void tearDownMethod() throws Exception {
  156. driver.close();
  157. }
  158.  
  159. public void automatedlogin() throws Exception {
  160. String title = "Hospital Software ";
  161. String url = "http://localhost/hospitalnew/appointment/appointments";
  162.  
  163. TestNavigationMenu object = new TestNavigationMenu();
  164. object.setUpMethod();
  165.  
  166. driver.navigate().to(url);
  167. driver.manage().window().maximize();
  168.  
  169. driver.navigate().to("http://localhost/hospitalnew/login");
  170. driver.manage().window().maximize();
  171.  
  172. element = driver.findElement(By.name("txtUserName__"));
  173. element.sendKeys(common.getUsername());
  174.  
  175. element = driver.findElement(By.name("txtPass__"));
  176. element.sendKeys(common.getPassword());
  177.  
  178. element = driver.findElement(By.name("submit"));
  179. element.click();
  180. }
  181.  
  182. @Test(priority = 1)
  183. public void login() throws Exception {
  184. String title = "Hospital Software ";
  185. String url = "http://localhost/hospitalnew/appointment/appointments";
  186.  
  187. TestNavigationMenu object = new TestNavigationMenu();
  188. object.setUpMethod();
  189.  
  190. driver.navigate().to(url);
  191. driver.manage().window().maximize();
  192.  
  193. driver.navigate().to("http://localhost/hospitalnew/login");
  194. driver.manage().window().maximize();
  195.  
  196. element = driver.findElement(By.name("txtUserName__"));
  197. element.sendKeys(common.getUsername());
  198.  
  199. element = driver.findElement(By.name("txtPass__"));
  200. element.sendKeys(common.getPassword());
  201.  
  202. element = driver.findElement(By.name("submit"));
  203. element.click();
  204.  
  205. if (driver.getTitle().equals(title)) {
  206. assertTrue(driver.getCurrentUrl().equals(url));
  207. }
  208.  
  209. object.tearDownMethod();
  210.  
  211. }
  212.  
  213. // test case 3
  214. @Test(priority = 2)
  215. public void isWorkingMastersDepartment() throws Exception {
  216. String title = "Hospital Software Department";
  217. String url = "http://localhost/hospitalnew/department/page";
  218.  
  219.  
  220. automatedlogin();
  221.  
  222. driver.navigate().to(url);
  223. driver.manage().window().maximize();
  224.  
  225. element = driver.findElement(By.className("dropdown-toggle"));
  226. element.click();
  227.  
  228. element = driver.findElement(By.className("dropdown-toggle"));
  229. element.click();
  230.  
  231. if (driver.getTitle().equals(title)) {
  232. assertTrue(driver.getCurrentUrl().equals(url));
  233. }
  234.  
  235. }
  236.  
  237. }
Add Comment
Please, Sign In to add comment