· 8 years ago · Jun 14, 2018, 03:06 PM
1
2import java.util.Random;
3import java.util.Set;
4import java.util.concurrent.TimeUnit;
5import java.util.function.Supplier;
6
7import org.openqa.selenium.By;
8import org.openqa.selenium.NoSuchElementException;
9import org.openqa.selenium.TimeoutException;
10import org.openqa.selenium.WebDriver;
11import org.openqa.selenium.WebElement;
12import org.openqa.selenium.chrome.ChromeDriver;
13import org.openqa.selenium.interactions.internal.Locatable;
14import org.openqa.selenium.support.FindBy;
15import org.openqa.selenium.support.PageFactory;
16import org.openqa.selenium.support.ui.ExpectedConditions;
17import org.openqa.selenium.support.ui.WebDriverWait;
18import org.testng.annotations.Test;
19
20import ru.vtsft.common.ThreadLocalDriver;
21import ru.vtsft.orvd.htmltest.TestBase;
22import ru.vtsft.orvd.htmltest.util.AbstractPage;
23import ru.yandex.qatools.htmlelements.element.HtmlElement;
24import ru.vtsft.orvd.htmltest.helpers.WithHelpers;
25import ru.vtsft.common.ThreadLocalDriver;
26import ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator;
27import ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementLocatorFactory;
28
29public class bot extends AbstractPage{
30
31 //веб Ñлементы, которые будут задейÑтвованы в Ñценарии
32 @FindBy(id = "signupform-email")
33 private WebElement vulcanLoginField;
34
35 @FindBy(id = "signupform-password")
36 private WebElement vulcanPwdField;
37
38 @FindBy(xpath = "//*[@id=\"signup-form\"]/div[2]/span/button")
39 private WebElement vulcanSignupButton;
40
41 @FindBy(xpath = "//div[@class = 'b-header js-head-hid']/div/div/div/a/span[@class = 'mail--inbox anim-inbox']")
42 private WebElement mailButton;
43
44 @FindBy(xpath = "//div[@id = 'modalCash']/div/div/span")
45 private WebElement modalCashWindowCloseIcon;
46
47 @FindBy(xpath = "//span[text() = 'Отправить пиÑьмо']")
48 private WebElement sendConfirmationEmailButton;
49
50 @FindBy (xpath = "//a[@data-g-label = 'sign in']")
51 private WebElement singinGmailButton;
52
53 @FindBy(id = "mailbox:login")
54 private WebElement mailLoginField;
55
56 @FindBy(id = "mailbox:password")
57 private WebElement mailPwdField;
58
59 @FindBy(xpath = "//input[@value='Войти']")
60 private WebElement mailSubmitButton;
61
62 @FindBy(xpath ="//span[text() = 'Ещё']")
63 private WebElement openMessageCategories;
64
65 @FindBy(xpath ="//a[text() = 'Спам (1)']")
66 private WebElement spam;
67
68 @FindBy(xpath ="//div[text()= 'Вулкан Platinum']")
69 //xpath = "//span[text() = 'Подтверждение почтового адреÑа']/parent::div")
70 private WebElement confirmationMessage;
71
72 @FindBy(xpath = "//b[text() = 'Потдвердить почту']")
73 private WebElement confirmMail;
74
75 @FindBy(xpath = "//span[@class='b-btn b-btn--red'][contains(text(),'пополнить')]")
76 private WebElement addFunds;
77
78 //[contains(text(),'пополнить')]
79
80 //@FindBy(xpath = "//img[@alt ='Qiwi]")
81
82 @FindBy(id ="payment-methods__item__qiwi")
83 private WebElement qiwi;
84
85 @FindBy(xpath = "span[@point ='100']")
86 private WebElement hundredRub;
87
88 @FindBy(id = "pay_amount")
89 private WebElement amountField;
90
91 @FindBy (id = "pay_requisites_phone_phone")
92 private WebElement payRequisites;
93
94 @FindBy (id = "pay-button")
95 private WebElement payButton;
96
97 @FindBy(id = "password")
98 private WebElement qiwiPassword;
99
100 @FindBy(id = "password-confirm")
101 private WebElement qiwiPasswordConfirm;
102
103 @FindBy(id = "smscode")
104 private WebElement smsCode;
105
106 @FindBy(xpath = "//button[@id - 'registerStepTwo']/span")
107 private WebElement qiwiApplyCode;
108
109 @FindBy(xpath = "//span[@class='b-btn b-btn--red'][contains(text(),'Включить Flash')]")
110 private WebElement flashButton;
111
112 @FindBy(xpath = "//*[@id='popular-games']/div[1]/div/div/div[2]/a[2]/span")
113 private WebElement playFirstGame;
114
115 @FindBy(xpath = "//*[@id='popular-games']/div[2]/div/div/div[2]/a[2]/span")
116 private WebElement playSecondGame;
117
118 //*[@id="popular-games"]/div[1]/div/div/a/img
119 //*[@id="popular-games"]/div[2]/div/div/a/img
120
121
122 /*
123 private static ThreadLocal<WebDriver> driverThreadLocal = new ThreadLocal<>();
124 private static Supplier<WebDriver> driverSupplier = ChromeDriver::new; // Chrome by default
125
126 public static void setDriverConstructor(Supplier<WebDriver> constructor) {
127 driverSupplier = constructor;
128 }
129
130
131 public static WebDriver get() {
132 if (driverThreadLocal.get() == null) driverThreadLocal.set(driverSupplier.get());
133 return driverThreadLocal.get();
134 }
135
136 protected WebDriver driver;
137 static Set<String> oldWindowsSet ;
138*/
139 //public bot(WebDriver driver) {
140 // this.driver = driver;
141 // PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this);
142// }
143// public bot() {
144// this.driver = ThreadLocalDriver.get();
145// PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(ThreadLocalDriver.get())), this);
146// }
147
148 // public static void quit() {
149 // if (driverThreadLocal.get() != null) {
150 // driverThreadLocal.get().quit();
151 // driverThreadLocal.remove();
152 // }
153 // }
154
155 //методы
156
157
158 public void navigateTo(String baseUrl) {
159 //Создаем объект веб-драйвера Ð´Ð»Ñ Ñ…Ñ€Ð¾Ð¼Ð°
160 // System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
161 // //String baseUrl="http://r.lt20.ru/9r65D:2619/";
162 //Создаем ÑкземплÑÑ€ драйвера
163 // WebDriver driver = new ChromeDriver();
164 //ÐеÑвное ожидание
165 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
166 //Разворачиваем окно на веÑÑŒ Ñкран
167 driver.manage().window().maximize();
168 driver.get(baseUrl);
169 }
170
171 public void goPlayGame(int gameNumber) {
172 driver.findElement(By.xpath("//*[@id=\"popular-games\"]/div["+gameNumber+"]/div/div/a/img")).click();
173 driver.findElement(By.xpath("//*[@id='popular-games']/div[" +gameNumber +"]/div/div/div[2]/a[2]/span")).click();
174 }
175
176 /**
177 * Ожидание пока Ñлемент Ñтанет кликабельным на Ñтранице
178 * @param driver
179 * @param element
180 */
181 public void waitForElementClickable(WebDriver driver, WebElement element){
182 timeSleep(1000);
183 (new WebDriverWait(driver, 90))
184 .until(ExpectedConditions.elementToBeClickable(element));
185 }
186
187
188
189 public void signup(WebElement loginField, WebElement pwdField,WebElement signupButton, String emailValue, String pwdValue) {
190 loginField.click();
191 loginField.clear();
192 loginField.sendKeys(emailValue);
193
194
195
196 pwdField.click();
197 pwdField.clear();
198 pwdField.sendKeys(pwdValue);
199
200 signupButton.click();
201 }
202
203 public void signupGmail(WebElement loginField, WebElement pwdField,WebElement signupButton, String emailValue, String pwdValue) {
204 loginField.click();
205 loginField.clear();
206 loginField.sendKeys(emailValue);
207
208 signupButton.click();
209
210 waitForElementClickable(driver, pwdField);
211 pwdField.click();
212 pwdField.clear();
213 pwdField.sendKeys(pwdValue);
214 signupButton.click();
215 }
216
217 protected void scrollToElement(WebElement element){
218 ((Locatable) element).getCoordinates().inViewPort();
219 }
220
221 public void payViaQiwi(String amountValue, String phoneValue) {
222 amountField.click();
223 amountField.clear();
224 amountField.sendKeys(amountValue);
225
226 payRequisites.click();
227 payRequisites.clear();
228 payRequisites.sendKeys(phoneValue);
229
230 payButton.click();
231
232
233
234
235 }
236 public void timeSleep(long miles) {
237 try {
238 Thread.sleep(miles);
239 } catch (InterruptedException e) {
240 // log or nothing
241 }
242 }
243
244
245 public void payQiwi(String amountValue, String payRequisitesValue) {
246 amountField.click();
247 amountField.clear();
248 amountField.sendKeys(amountValue);
249
250 payRequisites.click();
251 payRequisites.clear();
252 payRequisites.sendKeys(payRequisitesValue);
253
254 payButton.click();
255 }
256
257
258
259 //Ñценарий бота
260 @Test(enabled = true)
261 public void playerScenario() {
262
263
264 //пароль и логин вулкана принимать из файла, в который запиÑываютÑÑ Ð¿Ð°Ñ€Ð¾Ð»ÑŒ и логин почты
265 Random rand = new Random();
266 int code = rand.nextInt(100) + rand.nextInt(100) + rand.nextInt(100)+ rand.nextInt(100)+ rand.nextInt(100)+ rand.nextInt(100);
267
268 //String emailValue = "dfg" + code + "@gmailcom";
269 //String pwdValue = "pwd" +code + "!";
270 //tt0583805@gmail.com
271
272 String emailValue = "tester.testov.06@mail.ru";
273 String pwdValue = "123456[eq";
274
275 String amountValue ="100";
276 String payRequisitesValue = "";
277
278 //переходим по ÑÑылке, региÑтрируемÑÑ
279 navigateTo("http://r.lt20.ru/9r65D:2619/");
280 signup(vulcanLoginField, vulcanPwdField, vulcanSignupButton, emailValue,pwdValue);
281
282 //timeSleep(500);
283 //закрываем окно Ñ Ð¿Ð¾Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¸ÐµÐ¼ Ñчета
284 // modalCashWindowCloseIcon.click(); //поÑлÑетÑÑ Ñ‚Ð¾Ð»ÑŒÐºÐ¾ при первом входе в акаунт
285
286 //отправлÑем пиÑмьо подтверждениÑ
287 // waitForElementClickable(driver, sendConfirmationEmailButton); //только при первом прогоне, пока что теÑÑ‚ почты
288 // sendConfirmationEmailButton.click();
289
290 //переходим на почту, логинимÑÑ Ð¸ подтверждаем его
291 // navigateTo("https://mail.ru/");
292
293 // // timeSleep(1000);
294 // // singinGmailButton.click();
295
296 // signup(mailLoginField, mailPwdField, mailSubmitButton, emailValue,pwdValue);
297
298
299// confirmationMessage.click();
300
301// scrollToElement(confirmMail);
302// confirmMail.click();
303
304 //перебраÑывает на вулкан, пополнÑем Ñчет
305
306 addFunds.click();
307
308 //int x = driver.findElement(By.xpath("xxxxxxxxxxxx")).getLocation().getX();
309 //int y = driver.findElement(By.xpath("xxxxxxxxxxxx")).getLocation().getY();
310
311 qiwi.click(); //найти ÑпоÑоб выдернуть киви из меню
312
313 payQiwi(amountValue, payRequisitesValue); //оплата
314
315 // подтверждение платежа Ñ ÐºÐ°Ð¿Ñ‡ÐµÐ¹ и прочим..
316
317 //возвращаемÑÑ Ð½Ð° вулкан, идем играть в игры
318 goPlayGame(1);
319 }
320
321}