Advertisement
Guest User

Dice Login Project

a guest
Feb 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. package com.database;
  2.  
  3. import java.util.concurrent.TimeUnit;
  4.  
  5. import org.junit.After;
  6. import org.junit.Before;
  7. import org.junit.Test;
  8. import org.openqa.selenium.WebDriver;
  9. import org.openqa.selenium.firefox.FirefoxDriver;
  10. import org.openqa.selenium.remote.DesiredCapabilities;
  11.  
  12. public class EntryPoint {
  13.  
  14. WebDriver driver;
  15.  
  16. @Before
  17. public void setup() {
  18.  
  19. System.setProperty("webdriver.gecko.driver","C:\\Users\\erdog\\Desktop\\Java Class\\SeleniumDrivers\\geckodriver.exe");
  20. DesiredCapabilities capabilities=DesiredCapabilities.firefox();
  21. capabilities.setCapability("marionette", true);
  22.  
  23. driver = new FirefoxDriver(capabilities);
  24. driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS );
  25. }
  26.  
  27. @Test
  28. public void loginAsEmployee(){
  29. DiceLogin dlogin = new DiceLogin(driver);
  30.  
  31. //Clicking the Login/Register dropdown
  32. dlogin.clickLoginRegister();
  33.  
  34. //Entering the Username
  35. dlogin.enterUsername("text");
  36.  
  37. //Entering the Password
  38. dlogin.enterPassword("text");
  39.  
  40. //Clicking the Login button
  41. dlogin.clickLoginButton();
  42. }
  43.  
  44. @After
  45. public void close(){
  46. driver.close();
  47. }
  48.  
  49. }
  50.  
  51. ---------------------------------------------------------------------------------------------------------------------------------------
  52. package com.database;
  53.  
  54. import org.openqa.selenium.WebDriver;
  55. import org.openqa.selenium.WebElement;
  56. import org.openqa.selenium.support.FindBy;
  57. import org.openqa.selenium.support.How;
  58. import org.openqa.selenium.support.PageFactory;
  59.  
  60. public class DiceLogin {
  61.  
  62. WebDriver driver;
  63.  
  64. private static String baseUrl = "http://www.dice.com/";
  65.  
  66. @FindBy(how = How.ID, using="Login_1")
  67. WebElement loginRegister;
  68.  
  69. @FindBy(how=How.ID, using="Email_1")
  70. WebElement loginTextField;
  71.  
  72. @FindBy(how=How.ID, using ="Password_1")
  73. WebElement passwordTextField;
  74.  
  75. @FindBy(how=How.ID, using ="LoginBtn_1")
  76. WebElement loginButton;
  77.  
  78. public DiceLogin(WebDriver driver){
  79. this.driver = driver;
  80. driver.get(baseUrl);
  81. PageFactory.initElements(driver, this);
  82. }
  83.  
  84. public void clickLoginRegister(){
  85. loginRegister.click();
  86. }
  87. public void enterUsername(String text){
  88. loginTextField.sendKeys(text);
  89. }
  90. public void enterPassword(String text){
  91. passwordTextField.sendKeys(text);
  92. }
  93. public void clickLoginButton(){
  94. loginButton.click();
  95. }
  96. }
  97.  
  98. ---------------------------------------------------------------------------------------------------------------------------------------
  99.  
  100. package com.database;
  101.  
  102. import java.sql.Connection;
  103. import java.sql.DriverManager;
  104. import java.sql.ResultSet;
  105. import java.sql.SQLException;
  106. import java.sql.Statement;
  107.  
  108. public class dbexample {
  109.  
  110. public dbexample () throws Exception {
  111.  
  112. Connection connection=null;
  113. Statement statement = null;
  114.  
  115. try
  116. {
  117. // Register the JDBS driver
  118. Class.forName("com.mysql.jdbc.Driver");
  119. System.out.println("Database is registered");
  120.  
  121. //Opening Database connection
  122. connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/dicetest", "root", "mirchi89");
  123.  
  124. String sql = "select * from users";
  125. statement = connection.createStatement();
  126. ResultSet rs = statement.executeQuery(sql);
  127.  
  128. while(rs.next()){
  129. String studentname = rs.getString("email");
  130. System.out.println(studentname);
  131. }
  132.  
  133. } catch (ClassNotFoundException e) {
  134.  
  135. e.printStackTrace();
  136. }
  137. finally {
  138. connection.close();
  139. }
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement