Skip to content

Commit 92ba3ed

Browse files
author
jitendra pisal
committed
added code for updating ORT
1 parent 802154c commit 92ba3ed

File tree

6 files changed

+231
-19
lines changed

6 files changed

+231
-19
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.company.enumeration;
2+
3+
/**
4+
* Created by jitendra on 6/7/17.
5+
*/
6+
public enum VideoPlugin {
7+
main,osmf,bitmovin
8+
}

seleniumWebdriver/src/test/java/basepkg/BaseClass.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.log4j.PropertyConfigurator;
44
import org.openqa.selenium.WebDriver;
5+
import org.testng.annotations.AfterClass;
56
import org.testng.annotations.BeforeClass;
67
import org.testng.annotations.BeforeMethod;
78
import org.testng.annotations.BeforeSuite;
@@ -10,26 +11,18 @@
1011
/**
1112
* Created by jitendra on 29/5/17.
1213
*/
13-
public class BaseClass {
14-
15-
public WebDriver driver;
16-
private Util utils;
14+
public class BaseClass extends Util{
1715

1816
@BeforeSuite
19-
public void initUtils(){
20-
this.utils = new Util();
17+
public void init() throws Exception{
2118
String log4jConfPath = "src/test/java/log4j.properties";
2219
PropertyConfigurator.configure(log4jConfPath);
23-
}
24-
25-
@BeforeClass
26-
public void init() {
27-
driver = utils.getDriver(utils.getBrowser());
20+
driver.manage().window().maximize();
2821
}
2922

3023
@BeforeMethod
31-
public void maximize(){driver.manage().window().maximize();}
24+
public void maximize(){}
3225

33-
/*@AfterClass
34-
public void tearDown(){driver.close();driver.quit();}*/
26+
@AfterClass
27+
public void tearDown(){driver.close();driver.quit();}
3528
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package basics;
2+
3+
import basepkg.BaseClass;
4+
import org.openqa.selenium.By;
5+
import org.openqa.selenium.WebDriver;
6+
import org.openqa.selenium.WebElement;
7+
import org.testng.annotations.Test;
8+
9+
/**
10+
* Created by jitendra on 20/6/17.
11+
*/
12+
public class ShadowDOMExample extends BaseClass{
13+
14+
@Test
15+
public void shadowElement(){
16+
driver.get("http://www.google.com");
17+
WebElement ele = expandRootElement(driver);
18+
System.out.println("hi");
19+
20+
21+
}
22+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package basics;
2+
3+
import basepkg.BaseClass;
4+
import org.openqa.selenium.By;
5+
import org.openqa.selenium.StaleElementReferenceException;
6+
import org.openqa.selenium.WebElement;
7+
import org.openqa.selenium.support.ui.ExpectedConditions;
8+
import org.openqa.selenium.support.ui.WebDriverWait;
9+
import org.testng.Assert;
10+
import org.testng.annotations.Test;
11+
12+
import javax.swing.*;
13+
import java.util.List;
14+
15+
/**
16+
* Created by jitendra on 29/6/17.
17+
*/
18+
public class UpdateTickets extends BaseClass{
19+
20+
@Test(priority = 0)
21+
public void login(){
22+
driver.get("http://support.forgeahead.io/login.jsp?os_destination=%2Fsecure%2FDashboard.jspa");
23+
WebDriverWait wait = new WebDriverWait(driver,20);
24+
driver.findElement(By.id("login-form-username")).sendKeys(System.getProperty("username"));
25+
driver.findElement(By.id("login-form-password")).sendKeys(System.getProperty("password"));
26+
driver.findElement(By.id("login-form-submit")).click();
27+
}
28+
29+
@Test(priority = 1)
30+
public void updateTickets() throws InterruptedException {
31+
WebDriverWait wait = new WebDriverWait(driver,20);
32+
driver.switchTo().frame("gadget-10002");
33+
boolean isTrPresent = false;
34+
if (isTicketEmpty()) {
35+
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//table[@id='issuetable']")));
36+
isTrPresent = driver.findElement(By.xpath(".//table[@id='issuetable']/tbody/tr")).isDisplayed();
37+
}
38+
while(isTrPresent) {
39+
List<WebElement> allRows;
40+
try {
41+
allRows = driver.findElements(By.xpath(".//table[@id='issuetable']/tbody/tr"));
42+
}catch (Exception e){
43+
break;
44+
}
45+
String issueId = allRows.get(0).getAttribute("id");
46+
String isLeave = driver.findElement(By.xpath(".//tr[@id='"+issueId+"']//td[@class='nav summary']//a[@class='issue-link']")).getText();
47+
if (isLeave.contains("Leave")){
48+
driver.findElement(By.xpath(".//tr[@id='"+issueId+"']//td[@class='nav summary']//a[@class='issue-link']")).click();
49+
driver.findElement(By.ByClassName.xpath(".//ul[@id='opsbar-opsbar-transitions']//span[text()='Resolve Issue']")).click();
50+
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("issue-workflow-transition-submit")));
51+
driver.findElement(By.id("issue-workflow-transition-submit")).submit();
52+
}else {
53+
driver.findElement(By.xpath(".//tr[@id='" + issueId + "']//td[@class='nav summary']/p/a[contains(text(),'Automation')]")).click();
54+
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//a[@id='edit-issue']//span[text()='Edit']")));
55+
driver.findElement(By.xpath(".//a[@id='edit-issue']//span[text()='Edit']")).click();
56+
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("timetracking_originalestimate")));
57+
driver.findElement(By.id("timetracking_originalestimate")).click();
58+
driver.findElement(By.id("timetracking_originalestimate")).clear();
59+
driver.findElement(By.id("timetracking_originalestimate")).sendKeys("1d");
60+
driver.findElement(By.id("edit-issue-submit")).submit();
61+
62+
Thread.sleep(2000);
63+
64+
boolean breakIt = true;
65+
while (true) {
66+
breakIt = true;
67+
try {
68+
driver.findElement(By.xpath(".//a[@id='opsbar-operations_more']//span[text()='More']")).click();
69+
;
70+
} catch (Exception e) {
71+
if (e.getMessage().contains("element is not attached")) {
72+
breakIt = false;
73+
}
74+
}
75+
if (breakIt) {
76+
break;
77+
}
78+
79+
}
80+
81+
if (!driver.findElement(By.id("log-work")).isDisplayed()){
82+
driver.findElement(By.xpath(".//a[@id='opsbar-operations_more']//span[text()='More']")).click();
83+
}
84+
driver.findElement(By.id("log-work")).click();
85+
Thread.sleep(1000);
86+
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("log-work-time-logged")));
87+
driver.findElement(By.id("log-work-time-logged")).clear();
88+
driver.findElement(By.id("log-work-time-logged")).click();
89+
driver.findElement(By.id("log-work-time-logged")).sendKeys("1d");
90+
driver.findElement(By.id("log-work-submit")).submit();
91+
Thread.sleep(1000);
92+
driver.findElement(By.ByClassName.xpath(".//ul[@id='opsbar-opsbar-transitions']//span[text()='Resolve Issue']")).click();
93+
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("issue-workflow-transition-submit")));
94+
driver.findElement(By.id("issue-workflow-transition-submit")).submit();
95+
}
96+
driver.navigate().back();
97+
driver.switchTo().frame("gadget-10002");
98+
99+
if(isTicketEmpty()) {
100+
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//table[@id='issuetable']")));
101+
isTrPresent = driver.findElement(By.xpath(".//table[@id='issuetable']/tbody/tr")).isDisplayed();
102+
}else {
103+
isTrPresent = false;
104+
}
105+
}
106+
waitOnElement(10,By.id("header-details-user-fullname"));
107+
driver.findElement(By.id("header-details-user-fullname")).click();
108+
waitOnElement(10,By.id("log_out"));
109+
driver.findElement(By.id("log_out")).click();
110+
waitOnElement(10,By.xpath("//li[@id='user-options']//a[text()='Log In']"));
111+
Assert.assertTrue(waitOnElement(10,By.xpath("//li[@id='user-options']//a[text()='Log In']")),"User in not looged out successfully");
112+
System.out.println("Logged Out Successfully");
113+
}
114+
115+
@Test(priority = 2)
116+
public void logout(){
117+
/*waitOnElement(10,By.id("header-details-user-fullname"));
118+
driver.findElement(By.id("header-details-user-fullname")).click();
119+
waitOnElement(10,By.id("log_out"));
120+
driver.findElement(By.id("log_out")).click();
121+
waitOnElement(10,By.xpath("//li[@id='user-options']//a[text()='Log In']"));
122+
Assert.assertTrue(waitOnElement(10,By.xpath("//li[@id='user-options']//a[text()='Log In']")),"User in not looged out successfully");
123+
System.out.println("Logged Out Successfully");*/
124+
}
125+
126+
public boolean apply(WebElement element) {
127+
try {
128+
return !element.isDisplayed();
129+
} catch (StaleElementReferenceException elementHasDisappeared) {
130+
return true;
131+
}
132+
}
133+
134+
public boolean isTicketEmpty(){
135+
boolean flag = false;
136+
try{
137+
driver.findElement(By.className("empty-results"));
138+
System.out.println("No more tickets available for resolve");
139+
flag = false;
140+
}catch (Exception e){
141+
flag = true;
142+
}
143+
return flag;
144+
}
145+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package basics;
2+
3+
import basepkg.BaseClass;
4+
import org.openqa.selenium.By;
5+
import org.testng.annotations.Test;
6+
7+
/**
8+
* Created by jitendra on 30/6/17.
9+
*/
10+
public class UpdateTimeSheet extends BaseClass {
11+
12+
@Test
13+
public void updateTimeSheet(){
14+
driver.get("http://timesheet.forgeahead.io/");
15+
driver.findElement(By.id("loginSSO")).click();
16+
waitOnElement(20,By.name("email"));
17+
driver.findElement(By.name("email")).click();
18+
driver.findElement(By.name("email")).sendKeys("jitendra.pisal@forgeahead.io");
19+
driver.findElement(By.xpath("//input[@value='Login']")).click();
20+
}
21+
}

seleniumWebdriver/src/test/java/utilities/Util.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package utilities;
22

3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.JavascriptExecutor;
5+
import org.openqa.selenium.WebDriver;
6+
import org.openqa.selenium.WebElement;
37
import org.openqa.selenium.chrome.ChromeDriver;
48
import org.openqa.selenium.chrome.ChromeOptions;
59
import org.openqa.selenium.edge.EdgeDriver;
@@ -8,6 +12,8 @@
812
import org.openqa.selenium.remote.DesiredCapabilities;
913
import org.openqa.selenium.remote.RemoteWebDriver;
1014
import org.openqa.selenium.safari.SafariDriver;
15+
import org.openqa.selenium.support.ui.ExpectedConditions;
16+
import org.openqa.selenium.support.ui.WebDriverWait;
1117

1218
import java.net.MalformedURLException;
1319
import java.net.URL;
@@ -20,7 +26,7 @@ public class Util {
2026
private String browser;
2127
private String platform;
2228
private String mode;
23-
private RemoteWebDriver driver;
29+
public RemoteWebDriver driver;
2430
private String ipAddress;
2531
private DesiredCapabilities caps ;
2632

@@ -29,6 +35,7 @@ public Util(){
2935
this.platform = getPlatform();
3036
this.mode = getMode();
3137
this.ipAddress = getIpAddress();
38+
this.driver = getDriver(browser);
3239
}
3340

3441
/***
@@ -59,7 +66,7 @@ public String getPlatform(){
5966
public RemoteWebDriver initDriver(String browser) {
6067
if (browser == "chrome"){
6168
this.driver = new ChromeDriver();
62-
} else if (browser == "firefox"){
69+
} else if (browser.equals("firefox")){
6370
this.driver = new FirefoxDriver();
6471
} else if (browser == "internet explorer"){
6572
this.driver = new InternetExplorerDriver();
@@ -137,11 +144,11 @@ private RemoteWebDriver getRemoteDriver(String browser){
137144
}
138145

139146
try {
140-
driver = new RemoteWebDriver(new URL("http://"+ipAddress+"/wd/hub"), caps);
147+
this.driver = new RemoteWebDriver(new URL("http://"+ipAddress+"/wd/hub"), caps);
141148
} catch (MalformedURLException ex){
142149
System.out.println("driver is not initialising");
143150
}
144-
return driver;
151+
return this.driver;
145152
}
146153

147154
private void getDriversPath(String platform,String browser){
@@ -167,4 +174,20 @@ private void getDriversPath(String platform,String browser){
167174
System.setProperty("webdriver.egde.driver", "src/test/drivers/" + platform + "/MicrosoftWebDriver.exe");
168175
}
169176
}
170-
}
177+
178+
public WebElement expandRootElement(WebDriver driver){
179+
WebElement ele = (WebElement) ((JavascriptExecutor) driver).executeScript("return document.querySelector('settings-ui').shadowRoot.querySelector('#main').shadowRoot.querySelector('settings-basic-page').shadowRoot.querySelector('settings-privacy-page').shadowRoot.querySelector('#pages').querySelector('settings-subpage[page-title=\"Flash\"]').querySelector('category-default-setting').shadowRoot.querySelector('#toggle').shadowRoot.querySelector('#label')");
180+
return ele;
181+
}
182+
183+
public boolean waitOnElement(int seconds, By by){
184+
try {
185+
WebDriverWait wait = new WebDriverWait((RemoteWebDriver) this.driver, seconds);
186+
wait.until(ExpectedConditions.presenceOfElementLocated(by));
187+
return true;
188+
}catch (Exception e){
189+
e.getStackTrace();
190+
return false;
191+
}
192+
}
193+
}

0 commit comments

Comments
 (0)