-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHW3.java
More file actions
170 lines (133 loc) · 4.82 KB
/
HW3.java
File metadata and controls
170 lines (133 loc) · 4.82 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package Homework2;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Random;
import java.util.concurrent.TimeUnit;
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.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class HW3 {
WebDriver driver;
String browser;
String CompanyName;
String Name;
String email;
String phone;
String zip;
String address;
String state;
String city;
@BeforeTest
public void readHW() {
Properties property = new Properties();
//Input Stream, Buffer Reader, Scanner, File Reader - Class that can help us read any file
try{
InputStream inputs = new FileInputStream("data\\config.properties");
property.load(inputs);
browser = property.getProperty("browser");
CompanyName = property.getProperty("CompanyName");
Name = property.getProperty("Name");
email = property.getProperty("email");
phone = property.getProperty("phone");
zip = property.getProperty("zip");
address = property.getProperty("address");
state = property.getProperty("state");
city = property.getProperty("city");
}
catch(IOException e){
e.printStackTrace();
}
}
@BeforeClass
public void start() {
if(browser.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver", "drivers\\chromedriver.exe");
driver = new ChromeDriver();}
else if (browser.equalsIgnoreCase("FireFox"))
{System.setProperty("webdriver.gecko.driver", "drivers\\geckodriver.exe");
driver = new FirefoxDriver();}
}
@BeforeMethod
public void startbrowser() {
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://techfios.com/billing/?ng=login/");
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
String login = "demo@techfios.com";
String password = "abc123";
Assert.assertEquals(driver.getTitle(), "Login - iBilling", "Incorrect!");
By Username = By.xpath("//input[@id=\"username\"]");
By Password = By.xpath("//input[@id=\"password\"]");
By Login = By.xpath("//button[@name=\"login\"]");
driver.findElement(Username).sendKeys(login);
driver.findElement(Password).sendKeys(password);
driver.findElement(Login).click();
Assert.assertEquals(driver.getTitle(), "Dashboard- iBilling", "Wrong Page!!!!");}
@Test
public void Test() {
//By Class
By Customers = By.xpath("//span[contains(text(), \"Customers\")]");
By AddCustomer = By.xpath("//a[contains(text(), \"Add Customer\")]");
By FullName = By.xpath("//input[@id=\"account\"]");
By Email = By.xpath("//input[@id=\"email\"]");
By Phone = By.xpath("//input[@id=\"phone\"]");
By Address = By.xpath("//input[@id=\"address\"]");
By City = By.xpath("//input[@id=\"city\"]");
By State = By.xpath("//input[@id=\"state\"]");
By Zip = By.xpath("//input[@id=\"zip\"]");
By Submit = By.xpath("//button[@id=\"submit\"]");
By ListCustomers = By.xpath("//a[contains(text(),\"List Customers\")]");
By Company = By.xpath("//select[@id=\"cid\"]");
//Add Customer
driver.findElement(Customers).click();
WaitforElement(driver, 5, AddCustomer);
driver.findElement(AddCustomer).click();
int number = random();
WaitforElement(driver, 5, FullName);
driver.findElement(FullName).sendKeys(Name + number);
String name = Name + number;
select(Company, CompanyName);
driver.findElement(Email).sendKeys(number + email);
driver.findElement(Phone).sendKeys(number + phone);
driver.findElement(Address).sendKeys(address);
driver.findElement(City).sendKeys(city);
driver.findElement(State).sendKeys(state);
driver.findElement(Zip).sendKeys(zip);
driver.findElement(Submit).click();
driver.navigate().back();
WaitforElement(driver, 15, ListCustomers);
driver.findElement(ListCustomers).click();
WebElement find = driver.findElement(By.xpath("//table/tbody/tr/td[3]/a[contains(text(),\"Jim\")]"));
WaitforElement(driver, 15, ListCustomers);
Assert.assertEquals(find.getText(), name, "Is not displayed");
}
private int random() {
Random number = new Random();
return number.nextInt(999);
}
private void WaitforElement(WebDriver driver2, int TimeInSeconds, By locator) {
WebDriverWait wait = new WebDriverWait(driver, TimeInSeconds);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(locator));
}
private void select(By locator, String CompanyName) {
Select sel = new Select(driver.findElement(locator));
sel.selectByVisibleText(CompanyName);
}
//@AfterTest
public void end() {
driver.close();
driver.quit();
}
}