-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutomation.java
77 lines (55 loc) · 2.32 KB
/
Automation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package holapack;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
public class Automation {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","C:/Users/NAKUL LAKHOTIA/Documents/selenium/chromedriver.exe");
WebDriver driver = new ChromeDriver();
// Scenario- To login to a page
String baseUrl = "https://opensource-demo.orangehrmlive.com/index.php/auth/login";
driver.get(baseUrl);
WebElement userName = driver.findElement(By.xpath("//div/input[@name='txtUsername']"));
userName.sendKeys("Admin");
WebElement pass = driver.findElement(By.xpath("//div/input[@name='txtPassword']"));
pass.sendKeys("admin123");
WebElement login = driver.findElement(By.xpath("//div/input[@type='submit']"));
login.click();
// sleep for 3 seconds (implicit & explicit wait)
Thread.sleep(3000);
/*
// Scenario- To compare actual and expected
WebElement actualmsg = driver.findElement(By.xpath("//div[@id='forgotPasswordLink']/a"));
String actual=actualmsg.getText();
System.out.println("Actual message:"+actual);
String expected="Forgot your password?";
if(actual.equals(expected))
{
System.out.println("Pass");
}
else {
System.out.println("Fail");
}
*/
/*
// Scenario-Actions- To perform various actions on elements
WebElement perf = driver.findElement(By.xpath("//a[@id='menu__Performance']/b"));
Actions act=new Actions(driver);
act.moveToElement(perf).click().perform();
WebElement empTrack = driver.findElement(By.xpath("//a[@id='menu_performance_viewEmployeePerformanceTrackerList']"));
Actions act1=new Actions(driver);
act1.moveToElement(empTrack).click().perform();
*/
// Scenario-Select- Selecting from a drop down menu
WebElement leave = driver.findElement(By.xpath("//a[@id='menu_leave_viewLeaveModule']"));
Actions act=new Actions(driver);
act.moveToElement(leave).click().perform();
WebElement subUnit = driver.findElement(By.xpath("//select[@id='leaveList_cmbSubunit']"));
Select sel=new Select(subUnit);
sel.selectByVisibleText("Engineering");
driver.close();
}
}