-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbestbuyJava.txt
More file actions
236 lines (184 loc) · 11 KB
/
Copy pathbestbuyJava.txt
File metadata and controls
236 lines (184 loc) · 11 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import java.io.File;
import java.util.concurrent.TimeUnit;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
/**
*
* @author kylea
*/
public class doTest {
//9.25
// I'm sorry the last version I was told failed at the last step "P" complete order button
// I tried to fix that from happening.
//IF any failures occur within the order details page (name address and all that) then it wont restart anymore.
//I'm sorry, It was dumb to restart once it made it to the order page.
//This will now FREEZE if it fails on the order screen rather than RESTART. IT will play the alarm on freeze.
WebDriver driver;
WebDriverWait wait;
//I tried to make editing these fields easier. Update all the details here.
//I'm sorry I haven't tested logging into an account. IT maybe easier if it works. I Don't know.
String FirstName = "Saint";
String LastName = "Andrews";
String Address = "431 E Congress St";
String City = "Detroit";
String State = "Michigan";
String Zip = "48226";
String Email = "fakeemail@mail.com";
String CreditCard = "4111111111111111";
String Phone = "3139618961";
String expirationYear = "2020";
String expirationMonth = "11";
String CVV = "123";
boolean isDone = false;
public static void main(String[] args){
doTest tS = new doTest();
}
public doTest() {
System.setProperty("webdriver.chrome.driver", "D:\\Python\\Chromedriver\\chromedriver.exe");
driver = new ChromeDriver();
wait = new WebDriverWait(driver, 30);
this.doIt();
}
public void doIt(){
int Step = 1;
while (!isDone){
try{
//driver.get("https://www.bestbuy.com/site/sony-playstation-5-console/6426149.p?skuId=6426149");
driver.get("https://www.bestbuy.com/site/marvels-spider-man-miles-morales-ultimate-launch-edition-playstation-5/6430159.p?skuId=6430159");
String registryXpath = "//button[@data-test='registryListButton']";
String preorderXpath ="(//div[@Class='fulfillment-add-to-cart-button']//button)[1]";
Step = 2;
wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath(preorderXpath)));
WebElement preorderButton = driver.findElement(By.xpath(preorderXpath));
preorderButton.click();
Step = 3;
String viewCartXPATH = "//div[@class='go-to-cart-button']//a";
wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath(viewCartXPATH)));
WebElement viewCartButton = driver.findElement(By.xpath(viewCartXPATH));
viewCartButton.click();
Step = 4;
String shippingXpath = "//input[contains(@id,'shipping')]";
wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath(shippingXpath)));
WebElement shippingBtn = driver.findElement(By.xpath(shippingXpath));
shippingBtn.click();
Step = 5;
String checkoutXpath = "//button[@data-track='Checkout - Top']";
wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath(checkoutXpath)));
WebElement checkoutBtn = driver.findElement(By.xpath(checkoutXpath));
checkoutBtn.click();
Step = 6;
String guestXpath = "//button[contains(text(),'Continue')]";
wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath(guestXpath)));
WebElement guestBTN = driver.findElement(By.xpath(guestXpath));
guestBTN.click();
Step = 7;
String firstNameXpath = "//input[contains(@id,'firstName')]";
wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath(firstNameXpath)));
WebElement fNBt = driver.findElement(By.xpath(firstNameXpath));
fNBt.sendKeys(FirstName);
Step = 8;
String lastNameXpath = "//input[contains(@id,'lastName')]";
WebElement lNBt = driver.findElement(By.xpath(lastNameXpath));
lNBt.sendKeys(LastName);
Step = 9;
String addressXpath = "//input[contains(@id,'street')]";
WebElement adBt = driver.findElement(By.xpath(addressXpath));
adBt.sendKeys(Address);
Step = 10;
String cityXpath = "//input[contains(@id,'city')]";
WebElement ciBt = driver.findElement(By.xpath(cityXpath));
ciBt.sendKeys(City);
Step = 11;
String stateXpath = "//*[@name='state']";
WebElement stBt = driver.findElement(By.xpath(stateXpath));
//stBt.click();
stBt.sendKeys(State); //JS Set value?
Step = 12;
String zipcodeXpath = "//input[contains(@id,'zip')]";
WebElement ziBt = driver.findElement(By.xpath(zipcodeXpath));
ziBt.sendKeys(Zip);
Step = 13;
String emailXpath = "//input[contains(@id,'email')]";
WebElement emBt = driver.findElement(By.xpath(emailXpath));
emBt.sendKeys(Email);
Step = 14;
String phoneXpath = "//input[contains(@id,'phone')]";
WebElement phBt = driver.findElement(By.xpath(phoneXpath));
phBt.sendKeys(Phone);
//TimeUnit.SECONDS.sleep(30);
Step = 15;
String continueXpath = "(//span[contains(text(),'Continue')]//..)[1]";
WebElement continueBtn = driver.findElement(By.xpath(continueXpath));
continueBtn.click();
Step = 16;
String ccXpath = "//input[@id='optimized-cc-card-number']";
wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath(ccXpath)));
WebElement ccInput = driver.findElement(By.xpath(ccXpath));
ccInput.sendKeys(CreditCard);
Step = 17;
String expMoXpath = "//*[@name='expiration-month']";
WebElement expBtnMo = driver.findElement(By.xpath(expMoXpath));
expBtnMo.sendKeys(expirationMonth);
Step = 18;
String expYear = "//*[@name='expiration-year']";
WebElement expBtnYr = driver.findElement(By.xpath(expYear));
expBtnYr.sendKeys(expirationYear);
Step = 19;
String CCVXp = "//input[@id='credit-card-cvv']";
WebElement CcvIn = driver.findElement(By.xpath(CCVXp));
CcvIn.sendKeys(CVV);
Step = 20;
String completeorder = "//button[contains(@data-track,'Place your Order')]";
wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath(completeorder)));
WebElement completeBtn = driver.findElement(By.xpath(completeorder));
completeBtn.click();
String filePath = "C:\\Users\\kylea\\Downloads\\alarm.wav";
AudioInputStream alarm = AudioSystem.getAudioInputStream(new File(filePath).getAbsoluteFile());
Clip clip = AudioSystem.getClip();
clip.open(alarm);
clip.loop(Clip.LOOP_CONTINUOUSLY);
isDone = true;
}
catch(Exception e){
System.out.println("Failed at step: " + Step);
try{
String failedPath = "C:\\Users\\kylea\\Downloads\\speech.wav";
AudioInputStream failed = AudioSystem.getAudioInputStream(new File(failedPath).getAbsoluteFile());
Clip failedClip = AudioSystem.getClip();
failedClip.open(failed);
failedClip.start();
TimeUnit.SECONDS.sleep(60);
}
catch(Exception e){
System.out.println("exception " + e);
}
if (Step < 7) {
System.out.println("Looping. Did not make it to order screen.");
this.doIt();
}
// driver.quit();
//System.exit(0);
}
if (Step > 6){
System.out.println("Frozen-- Found error on order screen. But it's better to not loop from here.");
isDone = true;
try{
String filePath = "C:\\Users\\kylea\\Downloads\\alarm.wav";
AudioInputStream alarm = AudioSystem.getAudioInputStream(new File(filePath).getAbsoluteFile());
Clip clip = AudioSystem.getClip();
clip.open(alarm);
clip.loop(Clip.LOOP_CONTINUOUSLY);
}
catch(Exception e){
}
}
}
}
}