-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscenariofive.java
113 lines (80 loc) · 3.85 KB
/
scenariofive.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package holapack;
import java.util.List;
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 scenariofive {
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 create a new timesheet
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
Thread.sleep(3000);
WebElement time = driver.findElement(By.xpath("//a[@id='menu_time_viewTimeModule']/b"));
Actions act=new Actions(driver);
act.moveToElement(time).perform();
WebElement timeSheets = driver.findElement(By.xpath("//a[@id='menu_time_Timesheets']"));
Actions act1=new Actions(driver);
act1.moveToElement(timeSheets).click().perform();
WebElement mytimeSheets = driver.findElement(By.xpath("//a[@id='menu_time_viewMyTimesheet']"));
act1.moveToElement(mytimeSheets).click().perform();
// to select the date for timesheet
WebElement sheetWeek = driver.findElement(By.xpath("//select[@id='startDates']"));
Select sel=new Select(sheetWeek);
sel.selectByValue("1");
Thread.sleep(3000);
WebElement status = driver.findElement(By.xpath("//*[@id=\"timesheet_status\"]/h2"));
System.out.println(status.getText());
// to edit and add
WebElement edit = driver.findElement(By.xpath("//input[@id='btnEdit']"));
edit.click();
Thread.sleep(3000);
WebElement row = driver.findElement(By.xpath("//input[@id='initialRows_0_projectName']"));
row.clear();
row.sendKeys("gl");
// to select the item from the dropdown list
String searchText = "Global Corp and Co - Global Software phase - 1";
WebElement dropdown = driver.findElement(By.xpath("/html/body/div[4]"));
List<WebElement> options = dropdown.findElements(By.tagName("li"));
Thread.sleep(3000);
for (WebElement option : options)
{
if (option.getText().equals(searchText))
{
option.click(); // click the desired option
break;
}
}
// to select the activity name
Thread.sleep(4000); // need to wait for sometime so that dropdown can load
WebElement activity = driver.findElement(By.xpath("//select[@id='initialRows_0_projectActivityName']"));
Select sel1=new Select(activity);
sel1.selectByValue("7");
Thread.sleep(3000);
driver.findElement(By.xpath("//input[@id='initialRows_0_0']")).sendKeys("8:00");
driver.findElement(By.xpath("//input[@id='initialRows_0_1']")).sendKeys("8:00");
driver.findElement(By.xpath("//input[@id='initialRows_0_2']")).sendKeys("8:00");
driver.findElement(By.xpath("//input[@id='initialRows_0_3']")).sendKeys("8:00");
driver.findElement(By.xpath("//input[@id='initialRows_0_4']")).sendKeys("8:00");
driver.findElement(By.xpath("//input[@id='initialRows_0_5']")).sendKeys("0:00");
driver.findElement(By.xpath("//input[@id='initialRows_0_6']")).sendKeys("0:00");
driver.findElement(By.xpath("//input[@id='submitSave']")).click();
Thread.sleep(4000);
driver.findElement(By.xpath("//input[@id='btnSubmit']")).click();
Thread.sleep(3000);
WebElement newstatus = driver.findElement(By.xpath("//*[@id=\"timesheet_status\"]/h2"));
System.out.println(newstatus.getText());
driver.close();
}
}