-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtargetJava.txt
More file actions
129 lines (100 loc) · 5.65 KB
/
targetJava.txt
File metadata and controls
129 lines (100 loc) · 5.65 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
import java.awt.Robot;
import java.awt.event.KeyEvent;
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 doTarget {
WebDriver driver;
WebDriverWait wait;
public static void main(String[] args){
doTest tS = new doTarget();
}
public doTarget() {
System.setProperty("webdriver.chrome.driver", "D:\\Python\\Chromedriver\\chromedriver.exe");
driver = new ChromeDriver();
wait = new WebDriverWait(driver, 10);
this.doIt();
}
public void doIt(){
//9.25-- there's a fault in this code in that the preorder button when clicked isn't always successful
//so a failed notification pops up requiring clicks until it works
//then there's more after that. all of which I have modified on my own version not at the moment on git.
String Step = "A";
boolean isDone = false;
while (!isDone){
try{
driver.get("https://www.target.com/p/playstation-5-console/-/A-81114595");
//driver.get("https://www.target.com/p/playstation-5-hd-camera/-/A-81114478");
String registryXpath = "//button[@data-test='registryListButton']";
String preorderXpath ="//button[@data-test='preorderButton']";
Step = "A";
wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath(preorderXpath)));
System.out.println("Found preorder Button ");
Step = "B";
WebElement preorderButton = driver.findElement(By.xpath("//button[@data-test='preorderButton']"));
System.out.println("Found Preorder Button!!!!");
preorderButton.click();
Step = "C";
String declineCoverageXPATH = "//button[@data-test=\'espModalContent-declineCoverageButton\']";
wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath(declineCoverageXPATH)));
WebElement declineCoverageButton = driver.findElement(By.xpath(declineCoverageXPATH));
declineCoverageButton.click();
Step = "D";
String viewCartXPATH = "//button[@data-test=\'addToCartModalViewCartCheckout\']";
wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath(viewCartXPATH)));
WebElement viewCartButton = driver.findElement(By.xpath(viewCartXPATH));
viewCartButton.click();
Step = "E";
String checkoutXPATH = "//button[@data-test=\'checkout-button\']";
wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath(checkoutXPATH)));
WebElement checkoutButton = driver.findElement(By.xpath(checkoutXPATH));
checkoutButton.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;
Step = "H";
String LoginXpath = "//button[@id='login']";
WebElement loginButton = driver.findElement(By.xpath(LoginXpath));
loginButton.click();
loginButton = driver.findElement(By.xpath(LoginXpath));
loginButton.click();
Step = "I";
String readytoCheckoutXpath = "//button=[@data=test=\'checkout-button\']";
// WebElement readyToCheckoutButton = driver.findElement(By.xpath(readytoCheckoutXpath));
}
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(45);
}
catch(Exception e){
System.out.println("exception " + ee);
}
this.doIt();
// driver.quit();
//System.exit(0);
}
//isDone = true;
}
}
}