Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 0c48304

Browse files
Merge pull request #44 from SourcePointUSA/SP-4146_code_refactor_implement_log
SP-4146 code refactor and implement log messages
2 parents 2282921 + 7730d20 commit 0c48304

File tree

7 files changed

+338
-808
lines changed

7 files changed

+338
-808
lines changed

AutomationFramework/src/main/java/org/framework/helpers/Page.java

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
public class Page {
99

1010
WebDriver driver;
11+
public int timeOutInSeconds = 30;
1112

1213
public void clickElement(WebElement element) {
1314
element.click();

AutomationFramework/src/main/java/org/framework/pageObjects/ConsentViewPage.java

+13-54
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public class ConsentViewPage extends Page {
3636

3737
WebDriver driver;
3838

39-
public ConsentViewPage(WebDriver driver) throws InterruptedException {
40-
this.driver = driver;
41-
PageFactory.initElements(driver, this);
42-
logMessage("Initializing the "+this.getClass().getSimpleName()+" elements");
43-
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
44-
Thread.sleep(1000);
45-
}
39+
public ConsentViewPage(WebDriver driver) throws InterruptedException {
40+
this.driver = driver;
41+
PageFactory.initElements(driver, this);
42+
logMessage("Initializing the " + this.getClass().getSimpleName() + " elements");
43+
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
44+
Thread.sleep(1000);
45+
}
4646
// protected Report reporter = null;
4747

4848
@WithTimeout(time = 30, chronoUnit = ChronoUnit.SECONDS)
@@ -108,33 +108,9 @@ public ConsentViewPage(WebDriver driver) throws InterruptedException {
108108
boolean errorFound = false;
109109

110110
public WebElement eleButton(String buttonText) throws InterruptedException {
111-
Thread.sleep(3000);
112-
eleButton = (WebElement) driver
113-
.findElement(By.xpath("//XCUIElementTypeButton[@name='" + buttonText + "']"));
114-
Thread.sleep(3000);
115-
// eleButton = (WebElement) driver.findElement(By.("+buttonText+"));
116-
111+
eleButton = driver.findElement(By.xpath("//XCUIElementTypeButton[@name='" + buttonText + "']"));
112+
waitForElement(eleButton, timeOutInSeconds);
117113
return eleButton;
118-
119-
}
120-
121-
public void loadTime() {
122-
try {
123-
124-
long startTime = System.currentTimeMillis();
125-
new WebDriverWait(driver, 120).until(ExpectedConditions.presenceOfElementLocated(
126-
By.xpath("//android.webkit.WebView[contains(@text,'Notice Message App')]")));
127-
// new WebDriverWait(driver,
128-
// 60).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.Button[contains(@text,'Privacy
129-
// Setting')]")));
130-
long endTime = System.currentTimeMillis();
131-
long totalTime = endTime - startTime;
132-
System.out.println("**** Total Message Load Time: " + totalTime + " milliseconds");
133-
} catch (Exception ex) {
134-
System.out.println(ex);
135-
throw ex;
136-
}
137-
138114
}
139115

140116
public void scrollAndClick(String text) throws InterruptedException {
@@ -144,16 +120,9 @@ public void scrollAndClick(String text) throws InterruptedException {
144120
scrollObject.put("direction", "down");
145121
js.executeScript("mobile: scroll", scrollObject);
146122
js.executeScript("mobile: scroll", scrollObject);
147-
Thread.sleep(2000);
148-
149-
//driver.findElement(By.xpath("//XCUIElementTypeButton[@name='" + text + "']")).click();
150123
try {
151-
// long startTime = System.currentTimeMillis();
152-
// new WebDriverWait(driver, 120).until(ExpectedConditions.presenceOfElementLocated(
153-
// By.xpath("//XCUIElementTypeButton[@name='" + text + "']")));
154-
//
155124
driver.findElement(By.xpath("//XCUIElementTypeButton[@name='" + text + "']")).click();
156-
}catch(Exception ex){
125+
} catch (Exception ex) {
157126
throw ex;
158127
}
159128
}
@@ -182,27 +151,17 @@ public void expectedList() {
182151
}
183152

184153
public ArrayList<String> getConsentMessageDetails() throws InterruptedException {
185-
Thread.sleep(8000);
154+
WebElement ele = driver.findElement(By.xpath("//XCUIElementTypeButton[@name='Privacy Settings']"));
155+
156+
waitForElement(ele, timeOutInSeconds);
186157
for (WebElement msg : ConsentMessage) {
187158
consentMsg.add(msg.getText());
188159
// consentMsg.add(msg.getAttribute("value"));
189160
}
190161
return consentMsg;
191162
}
192163

193-
public void getLocation() {
194-
for (WebElement msg : ConsentMessage) {
195-
Point point = msg.getLocation();
196-
TouchAction touchAction = new TouchAction((PerformsTouchActions) driver);
197-
System.out.println("******************");
198-
System.out.println((point.x) + (msg.getSize().getWidth()));
199-
System.out.println((point.y) + (msg.getSize().getWidth()));
200-
System.out.println("******************");
201-
}
202-
}
203-
204164
public String verifyWrongCampaignError() throws InterruptedException {
205-
Thread.sleep(3000);
206165
try {
207166
return WrongCampaignErrorText.get(WrongCampaignErrorText.size() - 1).getText();
208167
} catch (Exception e) {

AutomationFramework/src/main/java/org/framework/pageObjects/NewSitePage.java

+1-38
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.appium.java_client.pagefactory.iOSFindBy;
2929
import io.appium.java_client.pagefactory.iOSXCUITFindBy;
3030
import io.appium.java_client.touch.offset.PointOption;
31+
import io.qameta.allure.Step;
3132

3233
public class NewSitePage extends Page {
3334
WebDriver driver;
@@ -94,14 +95,12 @@ public NewSitePage(WebDriver driver) throws InterruptedException {
9495
boolean paramFound = false;
9596

9697
public void selectCampaign(WebElement ele, String staggingValue) throws InterruptedException {
97-
9898
if (staggingValue.equals("ON")) {
9999
Point point = ele.getLocation();
100100
TouchAction touchAction = new TouchAction((PerformsTouchActions) driver);
101101

102102
touchAction.tap(PointOption.point(point.x + 20, point.y + 20)).perform();
103103
}
104-
Thread.sleep(3000);
105104
}
106105

107106
public void addTargetingParameter(WebElement paramKey, WebElement paramValue, String key, String value)
@@ -124,45 +123,9 @@ public void addTargetingParameter(WebElement paramKey, WebElement paramValue, St
124123

125124
}
126125

127-
public String getError() throws InterruptedException {
128-
boolean check = false;
129-
// waitForElement(ErrorMessage, 10);
130-
Thread.sleep(5000);
131-
int i = ErrorMessage.size();
132-
133-
String errorMsg = ErrorMessage.get(ErrorMessage.size() - 1).getText();
134-
return errorMsg;
135-
}
136-
137-
public boolean verifyError() throws InterruptedException {
138-
boolean check = false;
139-
// waitForElement(ErrorMessage, 10);
140-
Thread.sleep(3000);
141-
int i = ErrorMessage.size();
142-
143-
String errorMsg = ErrorMessage.get(ErrorMessage.size() - 1).getText();
144-
if (errorMsg.equals("Please enter targeting parameter key and value")) {
145-
check = true;
146-
}
147-
return check;
148-
}
149-
150126
public void waitForElement(WebElement ele, int timeOutInSeconds) {
151127
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
152128
wait.until(ExpectedConditions.visibilityOf(ele));
153129
}
154130

155-
public boolean verifyErrorMsg(String udid) throws InterruptedException {
156-
boolean check = false;
157-
// waitForElement(ErrorMessage, 10);
158-
Thread.sleep(3000);
159-
int i = ErrorMessage.size();
160-
161-
String errorMsg = ErrorMessage.get(ErrorMessage.size() - 1).getText();
162-
163-
if (errorMsg.equals("Please enter property details")) {
164-
check = true;
165-
}
166-
return check;
167-
}
168131
}

AutomationFramework/src/main/java/org/framework/pageObjects/PrivacyManagerPage.java

+6-14
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,15 @@ public void scrollAndClick(String text) throws InterruptedException {
7575
scrollObject.put("direction", "down");
7676
js.executeScript("mobile: scroll", scrollObject);
7777
js.executeScript("mobile: scroll", scrollObject);
78-
Thread.sleep(2000);
7978
driver.findElement(By.xpath("//XCUIElementTypeButton[@name='" + text + "']")).click();
8079

8180
}
8281

83-
public void loadTime() {
84-
long startTime = System.currentTimeMillis();
85-
new WebDriverWait(driver, 60).until(
86-
ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.Button[@text='Cancel']")));
87-
long endTime = System.currentTimeMillis();
88-
long totalTime = endTime - startTime;
89-
System.out.println("**** Total Privacy Manager Load Time: " + totalTime + " milliseconds");
90-
}
91-
9282
boolean privacyManageeFound = false;
9383

9484
public boolean isPrivacyManagerViewPresent() throws InterruptedException {
95-
Thread.sleep(8000);
96-
9785
try {
98-
// if (driver.findElements(By.xpath("//XCUIElementTypeStaticText[@name='FRENCH
99-
// Privacy Manager']")).size() > 0)
86+
waitForElement(ccpa_RejectAllButton, timeOutInSeconds);
10087
if (driver.findElements(By.xpath("//XCUIElementTypeStaticText[contains(@name,'Privacy Manager')]"))
10188
.size() > 0)
10289
privacyManageeFound = true;
@@ -113,5 +100,10 @@ public WebElement eleButton(String udid, String buttonText) {
113100
return eleButton;
114101

115102
}
103+
104+
public void waitForElement(WebElement ele, int timeOutInSeconds) {
105+
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
106+
wait.until(ExpectedConditions.visibilityOf(ele));
107+
}
116108

117109
}

0 commit comments

Comments
 (0)