Guest User

Untitled

a guest
Oct 28th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. public class OrderTest {
  2. private WebDriver driver;
  3. private String baseUrl;
  4. private StringBuffer verificationErrors = new StringBuffer();
  5.  
  6. @Before
  7. public void SetUp() throws Exception {
  8. System.setProperty("webdriver.gecko.driver", "C:\Users\egor\Documents\geckodriver.exe");
  9. driver = new FirefoxDriver();
  10. baseUrl = "https://www.natalie-tours.ru";
  11. }
  12.  
  13. @Test
  14. public void TestOrder() throws Exception{
  15. this.driver.get(baseUrl);
  16. this.driver.manage().window().maximize();
  17. WebElement countries = this.driver.findElement(By.id("countries"));
  18. countries.click();
  19. Select dropdownCountry = new Select(countries);
  20. dropdownCountry.selectByValue("18");
  21. WebElement myChosenCountry = dropdownCountry.getFirstSelectedOption();
  22. myChosenCountry.sendKeys(Keys.ENTER);
  23. String parentHandle = this.driver.getWindowHandle();
  24. WebElement selectZone = this.driver.findElement(By.id("zones"));
  25. selectZone.click();
  26. Select dropdownZone = new Select((selectZone));
  27. dropdownZone.selectByValue("16");
  28. WebElement myChosenZone = dropdownZone.getFirstSelectedOption();
  29. myChosenZone.sendKeys(Keys.ENTER);
  30. WebElement searchButton = this.driver.findElement(By.cssSelector("input[type="submit"]"));
  31. searchButton.click();
  32. Thread.sleep(10000);
  33. Set<String> windows = this.driver.getWindowHandles();
  34. System.out.println(windows.size());
  35. Iterator iterator = windows.iterator();
  36. String currentWindowId;
  37.  
  38. while (iterator.hasNext()){
  39. currentWindowId = iterator.next().toString();
  40. if (!currentWindowId.equals(parentHandle)){
  41. this.driver.switchTo().window(currentWindowId);
  42. WebElement buttonOpt = this.driver.findElement(By.xpath("//*[@id="moreInfo1293951883"]/button/span"));
  43. buttonOpt.click();
  44. }
  45. }
  46.  
  47. Thread.sleep(10000);
  48.  
  49. }
  50.  
  51. private boolean isElementPresent(By by) {
  52. try {
  53. driver.findElement(by);
  54. return true;
  55. } catch (NoSuchElementException e) {
  56. return false;
  57. }
  58. }
  59.  
  60. private boolean isAlertPresent() {
  61. try {
  62. driver.switchTo().alert();
  63. return true;
  64. } catch (NoAlertPresentException e) {
  65. return false;
  66. }
  67. }
  68.  
  69. while (iterator.hasNext()){
  70. currentWindowId = iterator.next().toString();
  71. if (!currentWindowId.equals(parentHandle)){
  72. this.driver.switchTo().window(currentWindowId);
  73. WebElement frame = driver.findElement(By.id("STD_SEARCHER"));
  74. driver.switchTo().frame(frame);
  75. WebElement buttonOpt = this.driver.findElement(By.xpath("//*[@id='moreInfo1293951883']/button/span"));
  76. buttonOpt.click();
  77. }
  78. }
Add Comment
Please, Sign In to add comment