-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathTestUtil.java
More file actions
102 lines (87 loc) · 3.9 KB
/
TestUtil.java
File metadata and controls
102 lines (87 loc) · 3.9 KB
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
package com.crm.qa.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import com.crm.qa.base.TestBase;
public class TestUtil extends TestBase {
public static long PAGE_LOAD_TIMEOUT = 20;
public static long IMPLICIT_WAIT = 20;
public static String TESTDATA_SHEET_PATH = System.getProperty("user.dir")+ "/src/main/java/com/crm" + "/qa/testdata/FreeCrmTestData.xlsx";
static Workbook book;
static Sheet sheet;
static JavascriptExecutor js;
public void switchToFrame() {
driver.switchTo().frame("mainpanel");
}
public static Object[][] getTestData(String sheetName) {
FileInputStream file = null;
try {
file = new FileInputStream(TESTDATA_SHEET_PATH);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
book = WorkbookFactory.create(file);
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
sheet = book.getSheet(sheetName);
Object[][] data = new Object[sheet.getLastRowNum()][sheet.getRow(0).getLastCellNum()];
// System.out.println(sheet.getLastRowNum() + "--------" +
// sheet.getRow(0).getLastCellNum());
for (int i = 0; i < sheet.getLastRowNum(); i++) {
for (int k = 0; k < sheet.getRow(0).getLastCellNum(); k++) {
data[i][k] = sheet.getRow(i + 1).getCell(k).toString();
// System.out.println(data[i][k]);
}
}
return data;
}
public static void takeScreenshotAtEndOfTest() throws IOException {
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String currentDir = System.getProperty("user.dir");
FileUtils.copyFile(scrFile, new File(currentDir + "/screenshots/" + System.currentTimeMillis() + ".png"));
}
public static void runTimeInfo(String messageType, String message) throws InterruptedException {
js = (JavascriptExecutor) driver;
// Check for jQuery on the page, add it if need be
js.executeScript("if (!window.jQuery) {"
+ "var jquery = document.createElement('script'); jquery.type = 'text/javascript';"
+ "jquery.src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js';"
+ "document.getElementsByTagName('head')[0].appendChild(jquery);" + "}");
Thread.sleep(5000);
// Use jQuery to add jquery-growl to the page
js.executeScript("$.getScript('https://the-internet.herokuapp.com/js/vendor/jquery.growl.js')");
// Use jQuery to add jquery-growl styles to the page
js.executeScript("$('head').append('<link rel=\"stylesheet\" "
+ "href=\"https://the-internet.herokuapp.com/css/jquery.growl.css\" " + "type=\"text/css\" />');");
Thread.sleep(5000);
// jquery-growl w/ no frills
js.executeScript("$.growl({ title: 'GET', message: '/' });");
//'"+color+"'"
if (messageType.equals("error")) {
js.executeScript("$.growl.error({ title: 'ERROR', message: '"+message+"' });");
}else if(messageType.equals("info")){
js.executeScript("$.growl.notice({ title: 'Notice', message: 'your notice message goes here' });");
}else if(messageType.equals("warning")){
js.executeScript("$.growl.warning({ title: 'Warning!', message: 'your warning message goes here' });");
}else
System.out.println("no error message");
// jquery-growl w/ colorized output
// js.executeScript("$.growl.error({ title: 'ERROR', message: 'your error message goes here' });");
// js.executeScript("$.growl.notice({ title: 'Notice', message: 'your notice message goes here' });");
// js.executeScript("$.growl.warning({ title: 'Warning!', message: 'your warning message goes here' });");
Thread.sleep(5000);
}
}