Guest User

Untitled

a guest
Oct 1st, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 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. import common.common;
  106. import java.util.concurrent.TimeUnit;
  107. import org.openqa.selenium.By;
  108. import org.openqa.selenium.WebDriver;
  109. import org.openqa.selenium.WebElement;
  110. import org.openqa.selenium.chrome.ChromeDriver;
  111. import static org.testng.Assert.*;
  112. import org.testng.annotations.AfterClass;
  113. import org.testng.annotations.AfterMethod;
  114. import org.testng.annotations.BeforeClass;
  115. import org.testng.annotations.BeforeMethod;
  116. import org.testng.annotations.Test;
  117.  
  118. /**
  119. *
  120. * @author Aruns
  121. */
  122. public class TestNavigationMenu {
  123.  
  124. public TestNavigationMenu() {
  125. }
  126.  
  127. // TODO add test methods here.
  128. // The methods must be annotated with annotation @Test. For example:
  129. //
  130. // @Test
  131. // public void hello() {}
  132. WebDriver driver;
  133. common common;
  134. WebElement element;
  135.  
  136. @BeforeClass
  137. public static void setUpClass() throws Exception {
  138. }
  139.  
  140. @AfterClass
  141. public static void tearDownClass() throws Exception {
  142. }
  143.  
  144. @BeforeMethod
  145. public void setUpMethod() throws Exception {
  146. common = new common();
  147. System.setProperty("webdriver.chrome.driver", common.getChromeDriver());
  148. driver = new ChromeDriver();
  149. driver.manage().timeouts().implicitlyWait(common.getTimeout(), TimeUnit.SECONDS);
  150. }
  151.  
  152. @AfterMethod
  153. public void tearDownMethod() throws Exception {
  154. driver.close();
  155. }
  156.  
  157. public void automatedlogin() throws Exception {
  158. String title = "Hospital Software ";
  159. String url = "http://localhost/hospitalnew/appointment/appointments";
  160.  
  161. TestNavigationMenu object = new TestNavigationMenu();
  162. object.setUpMethod();
  163.  
  164. driver.navigate().to(url);
  165. driver.manage().window().maximize();
  166.  
  167. driver.navigate().to("http://localhost/hospitalnew/login");
  168. driver.manage().window().maximize();
  169.  
  170. element = driver.findElement(By.name("txtUserName__"));
  171. element.sendKeys(common.getUsername());
  172.  
  173. element = driver.findElement(By.name("txtPass__"));
  174. element.sendKeys(common.getPassword());
  175.  
  176. element = driver.findElement(By.name("submit"));
  177. element.click();
  178. }
  179.  
  180. @Test(priority = 1)
  181. public void login() throws Exception {
  182. String title = "Hospital Software ";
  183. String url = "http://localhost/hospitalnew/appointment/appointments";
  184.  
  185. TestNavigationMenu object = new TestNavigationMenu();
  186. object.setUpMethod();
  187.  
  188. driver.navigate().to(url);
  189. driver.manage().window().maximize();
  190.  
  191. driver.navigate().to("http://localhost/hospitalnew/login");
  192. driver.manage().window().maximize();
  193.  
  194. element = driver.findElement(By.name("txtUserName__"));
  195. element.sendKeys(common.getUsername());
  196.  
  197. element = driver.findElement(By.name("txtPass__"));
  198. element.sendKeys(common.getPassword());
  199.  
  200. element = driver.findElement(By.name("submit"));
  201. element.click();
  202.  
  203. if (driver.getTitle().equals(title)) {
  204. assertTrue(driver.getCurrentUrl().equals(url));
  205. }
  206.  
  207. object.tearDownMethod();
  208.  
  209. }
  210.  
  211. // test case 3
  212. @Test(priority = 2)
  213. public void isWorkingMastersDepartment() throws Exception {
  214. String title = "Hospital Software Department";
  215. String url = "http://localhost/hospitalnew/department/page";
  216.  
  217.  
  218. automatedlogin();
  219.  
  220. driver.navigate().to(url);
  221. driver.manage().window().maximize();
  222.  
  223. element = driver.findElement(By.className("dropdown-toggle"));
  224. element.click();
  225.  
  226. element = driver.findElement(By.className("dropdown-toggle"));
  227. element.click();
  228.  
  229. if (driver.getTitle().equals(title)) {
  230. assertTrue(driver.getCurrentUrl().equals(url));
  231. }
  232.  
  233. }
  234.  
  235. }
Add Comment
Please, Sign In to add comment