@Test public void testOtsi() throws Exception { driver.get(baseUrl + "/"); driver.findElement(By.linkText("Kandidaadid")).click(); // Warning: waitForTextPresent may require manual changes for (int second = 0; ; second++) { if (second >= 60) fail("timeout"); try { if (driver .findElement(By.cssSelector("BODY")) .getText() .matches("^[\\s\\S]*Vana Kala[\\s\\S]*$")) break; } catch (Exception e) { } Thread.sleep(1000); } driver.findElement(By.id("nimi")).clear(); driver.findElement(By.id("nimi")).sendKeys("Magdalena"); try { assertEquals("Magdalena", driver.findElement(By.id("nimi")).getAttribute("value")); } catch (Error e) { verificationErrors.append(e.toString()); } driver.findElement(By.id("sButton")).click(); // Warning: waitForTextPresent may require manual changes for (int second = 0; ; second++) { if (second >= 60) fail("timeout"); try { if (driver .findElement(By.cssSelector("BODY")) .getText() .matches("^[\\s\\S]*Magdalena Malejeva[\\s\\S]*$")) break; } catch (Exception e) { } Thread.sleep(1000); } // Warning: verifyTextNotPresent may require manual changes try { assertFalse( driver .findElement(By.cssSelector("BODY")) .getText() .matches("^[\\s\\S]*Vana Kala[\\s\\S]*$")); } catch (Error e) { verificationErrors.append(e.toString()); } }
private void ActivitiesOfInterest() throws IOException { // Click Activities of Interest driver .findElement( By.xpath( "//ul[@class='vertical-tabs-list']/li/a/strong[contains(text(), \"Activities of Interest\")]")) .click(); // Click Student Newspaper Checkbox // TODO Do not use number in locator driver.findElement(By.xpath("//div[11]/input")).click(); // Click TV Station Checkbox // TODO Do not use number in locator driver.findElement(By.xpath("//div[13]/input")).click(); // Click Apply driver.findElement(By.id("edit-activities-interests-apply-filter")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
@After public void tearDown() throws Exception { String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } }
private void AreaOfStudy() throws IOException, InterruptedException { // Click Area of School driver .findElement( By.xpath( "//ul[@class='vertical-tabs-list']/li/a/strong[contains(text(), \"Area of Study\")]")) .click(); // Select One Area Study new Select(driver.findElement(By.id("edit-area-of-study-parent"))) .selectByVisibleText("Area, Ethnic, Cultural, and Gender Studies"); // Wait For Another Select List To Load Thread.sleep(5000); // Select Subareas of Study new Select(driver.findElement(By.xpath("//div[@id='child-area-of-study-wrapper']//select"))) .selectByVisibleText("Area, Ethnic, Cultural, and Gender Studies, Other"); // Click Apply driver.findElement(By.id("edit-area-of-study-apply-filter")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
private void SpecialNeeds() throws IOException { // Click Special Needs driver .findElement( By.xpath( "//ul[@class='vertical-tabs-list']/li/a/strong[contains(text(), \"Special Needs\")]")) .click(); // Select Special Needs Select SpecialNeeds = new Select(driver.findElement(By.id("edit-special-needs"))); // Select Learning Center SpecialNeeds.selectByVisibleText("Learning Center"); // Select Early Syllabus SpecialNeeds.selectByVisibleText("Early syllabus"); // Click Apply driver.findElement(By.id("edit-special-needs-apply-filter")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
private void TypesOfSchool() throws IOException { // Click Type of School driver.findElement(By.cssSelector("strong")).click(); // Click Private driver.findElement(By.id("edit-public-private-private")).click(); // Move School Size Slider // TODO Slider not working properly WebElement Slider1 = driver.findElement(By.id("population_jq_slider")); Actions moveSlider1 = new Actions(driver); Action action1 = moveSlider1.dragAndDropBy(Slider1, 0, 10).build(); action1.perform(); // Select Religious Affiliation new Select(driver.findElement(By.id("edit-religious-affiliation"))) .selectByVisibleText("Church of Christ"); // Move Tuition Range Slider // TODO Slider not working properly WebElement Slider2 = driver.findElement(By.id("tuition_range_jq_slider")); Actions moveSlider2 = new Actions(driver); Action action2 = moveSlider2.dragAndDropBy(Slider2, 0, 10).build(); action2.perform(); // Click Apply driver.findElement(By.id("edit-type-of-school-apply-filter")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
private void Location() throws IOException { // Click Location driver .findElement( By.xpath( "//ul[@class='vertical-tabs-list']/li/a/strong[contains(text(), \"Location\")]")) .click(); // Click West Checkbox // TODO Do not use number in Locator driver.findElement(By.xpath("//fieldset[6]/div/div[4]/div/div[3]/input")).click(); // Click South Checkbox // TODO Do not use number in Locator driver.findElement(By.xpath("//fieldset[6]/div/div[4]/div/div[6]/input")).click(); // Click Apply driver.findElement(By.id("edit-location-apply-filter")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
@Test public void testGotoFinalReview() throws Exception { // Goto Final Review page driver.findElement(By.xpath("//a[contains(text(), 'Final Review')]")).click(); try { assertEquals( "Final Review", driver.findElement(By.xpath("//*[@id='container']/h3")).getText()); } catch (Error e) { screenShots.takeScreenShot("gotoFinalReview"); verificationErrors.append(e.toString()); } Thread.sleep(300); // Find where the warning is displayed and scroll it into view, then screenshot it. // We look for 'Scholarship and Sponsorship' since the warning is in the 'Qualifications' area // and the scrolling is causing a heading right where we scroll to and covers it. WebElement elem = driver.findElement(By.xpath("//h4[contains(text(), 'Scholarship and Sponsorship')]")); ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", elem); Thread.sleep(300); screenShots.takeScreenShot("FinalReviewWarnMsgNoQualifEntrd"); // Go back to application driver.findElement(By.cssSelector("#link_to_application > span")).click(); }
@AfterMethod public void tearDown() throws Exception { driver.quit(); String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { AssertJUnit.fail(verificationErrorString); } }
@After public void tearDown() throws Exception { recorder.stopRecording(); driver.quit(); String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } }
@Test public void testWeather() throws Exception { driver.get(baseUrl + "/"); driver.findElement(By.linkText("Edmonton")).click(); for (int second = 0; ; second++) { if (second >= 60) fail("timeout"); try { if (isElementPresent(By.id("cityjump"))) break; } catch (Exception e) { } Thread.sleep(1000); } // Warning: verifyTextPresent may require manual changes try { assertTrue( driver .findElement(By.cssSelector("BODY")) .getText() .matches("^[\\s\\S]*Current Conditions[\\s\\S]*$")); } catch (Error e) { verificationErrors.append(e.toString()); } // Warning: verifyTextPresent may require manual changes try { assertTrue( driver .findElement(By.cssSelector("BODY")) .getText() .matches("^[\\s\\S]*Forecast[\\s\\S]*$")); } catch (Error e) { verificationErrors.append(e.toString()); } // Warning: verifyTextPresent may require manual changes try { assertTrue( driver .findElement(By.cssSelector("BODY")) .getText() .matches("^[\\s\\S]*Edmonton City Centre Airport[\\s\\S]*$")); } catch (Error e) { verificationErrors.append(e.toString()); } }
private void SearchButton() throws IOException { // Enter Text To Be Search driver.findElement(By.id("edit-keys")).clear(); driver.findElement(By.id("edit-keys")).sendKeys("Abilene"); // Click Search driver.findElement(By.id("edit-submit")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
@Test( dataProvider = "addNewAgentApplicant", dataProviderClass = applicantDataInternationalNewApplicant.class) public void testEnterDataAddNewApplicant( String loginEmail, String loginPassword, String firstName, String lastName, String birthDay, String birthMonth, String birthYear) throws Exception { // Add new applicant to Agent Thread.sleep(300); // Test case from HERE to CITIZENSHIP will fail if the applicant already exists. driver.findElement(By.id("field-email")).clear(); driver.findElement(By.id("field-email")).sendKeys(loginEmail); Thread.sleep(150); driver.findElement(By.id("field-confirmEmail")).clear(); driver.findElement(By.id("field-confirmEmail")).sendKeys(loginEmail); Thread.sleep(100); driver.findElement(By.id("field-firstName")).clear(); driver.findElement(By.id("field-firstName")).sendKeys(firstName); driver.findElement(By.id("field-lastName")).clear(); driver.findElement(By.id("field-lastName")).sendKeys(lastName); new Select(driver.findElement(By.name("dayOfBirth"))).selectByVisibleText(birthDay); new Select(driver.findElement(By.name("monthOfBirth"))).selectByVisibleText(birthMonth); new Select(driver.findElement(By.name("yearOfBirth"))).selectByVisibleText(birthYear); driver.findElement(By.xpath("//button[@type='submit']")).click(); System.out.println("Applicant = " + loginEmail); Thread.sleep(500); try { assertEquals( "Profile Information", driver.findElement(By.cssSelector("h3.col-xs-12")).getText()); } catch (Error e) { screenShots.takeScreenShot("enterDataAddNewAppl"); verificationErrors.append(e.toString()); } }
@Test( dataProvider = "addCitizenshipInfo", dataProviderClass = applicantDataDomesticNewApplicant.class) public void testEnterDataCitizenshipResidencyDomestic( String citizenshipType, String domesticType, String fieldCitizenshipCountryId, String fieldBirthCountryId, String fieldResidenceCountryId, String ATSI) throws Exception { // Enter Citizenship driver.findElement(By.id(citizenshipType)).click(); driver.findElement(By.id(domesticType)).click(); Thread.sleep(300); selectFromSelect2.SelectDropDownOption("field-birthCountryId", fieldBirthCountryId); Thread.sleep(300); selectFromSelect2.SelectDropDownOption("field-residenceCountryId", fieldResidenceCountryId); driver.findElement(By.id("field-" + ATSI)).click(); driver.findElement(By.xpath("//input[@value='Save']")).click(); for (int second = 0; ; second++) { if (second >= 60) fail("timeout"); try { if ("Saved".equals(driver.findElement(By.cssSelector("div.toast-message")).getText())) break; } catch (Exception e) { screenShots.takeScreenShot("enterDataCitResDom1"); } Thread.sleep(1000); } // Goto Home or Dashboard driver.findElement(By.cssSelector("span.link-to-dashboard.dashboard-text")).click(); try { assertEquals( "Profile Information", driver.findElement(By.cssSelector("h3.col-xs-12")).getText()); } catch (Error e) { screenShots.takeScreenShot("enterDataCitResDom2"); verificationErrors.append(e.toString()); } }
private void Sports() throws IOException { // Click Sports driver .findElement( By.xpath("//ul[@class='vertical-tabs-list']/li/a/strong[contains(text(), \"Sports\")]")) .click(); // Select Sports Select Sports = new Select(driver.findElement(By.id("edit-varsity-sports"))); // Select Baseball Sports.selectByVisibleText("baseball"); // Select Basketball Sports.selectByVisibleText("basketball"); // Click Apply driver.findElement(By.id("edit-varsity-sports-apply-filter")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
@Test public void testRegistreerimine() throws Exception { driver.get(baseUrl + "/login"); driver.findElement(By.xpath("//button[5]")).click(); driver.findElement(By.id("kasutajanimi")).clear(); driver.findElement(By.id("kasutajanimi")).sendKeys("Testkasutaja"); driver.findElement(By.id("eesnimi")).clear(); driver.findElement(By.id("eesnimi")).sendKeys("Test"); driver.findElement(By.id("perenimi")).clear(); driver.findElement(By.id("perenimi")).sendKeys("Kasutaja"); driver.findElement(By.id("parool")).clear(); driver.findElement(By.id("parool")).sendKeys("testkasutaja"); driver.findElement(By.id("email")).clear(); driver.findElement(By.id("email")).sendKeys("*****@*****.**"); driver.findElement(By.id("telnr")).clear(); driver.findElement(By.id("telnr")).sendKeys("55123123"); driver.findElement(By.id("regamisnupp")).click(); try { assertEquals( "Registreerimine õnnestus!", driver.findElement(By.xpath("//div/div/div/div")).getText()); } catch (Error e) { verificationErrors.append(e.toString()); } }
@Test( dataProvider = "addNewApplicant", dataProviderClass = applicantDataDomesticNewApplicant.class) public void testRegisterAccount( String loginEmail, String loginPassword, String firstName, String lastName, String birthDay, String birthMonth, String birthYear) throws Exception { // Register New Account driver.findElement(By.id("field-firstName")).clear(); driver.findElement(By.id("field-firstName")).sendKeys(firstName); driver.findElement(By.id("field-lastName")).clear(); driver.findElement(By.id("field-lastName")).sendKeys(lastName); new Select(driver.findElement(By.name("day"))).selectByVisibleText(birthDay); new Select(driver.findElement(By.name("month"))).selectByVisibleText(birthMonth); new Select(driver.findElement(By.name("year"))).selectByVisibleText(birthYear); driver.findElement(By.id("field-email")).clear(); driver.findElement(By.id("field-email")).sendKeys(loginEmail); driver.findElement(By.id("field-confirmEmail")).clear(); driver.findElement(By.id("field-confirmEmail")).sendKeys(loginEmail); driver.findElement(By.id("field-password")).clear(); driver.findElement(By.id("field-password")).sendKeys(loginPassword); driver.findElement(By.id("field-confirmPassword")).clear(); driver.findElement(By.id("field-confirmPassword")).sendKeys(loginPassword); driver.findElement(By.id("field-terms")).click(); driver.findElement(By.xpath("(//button[@type='submit'])[2]")).click(); try { assertEquals( "Successfully registered.", driver.findElement(By.cssSelector("div.alert.alert-success")).getText()); } catch (Error e) { screenShots.takeScreenShot("registerAcct_outp"); verificationErrors.append(e.toString()); } System.out.println("Applicant = " + loginEmail + " Password = " + loginPassword); // Write out the Applicants email address to the output file created in gotoSite.java // First create object of java FileWriter and BufferedWriter class. String WriteFile = generateFileName(); FileWriter FW = new FileWriter(WriteFile); BufferedWriter BW = new BufferedWriter(FW); BW.write(loginEmail); // Writing applicants login to File. BW.newLine(); // To write next string on new line. BW.write(lastName); // Writing applicants lastname to File. BW.newLine(); // To write next string on new line. BW.write(firstName); // Writing applicants first name to File. BW.newLine(); // To write next string on new line. BW.close(); }
// li.active>span.next public static void main(String[] args) { if (args.length < 2) { System.out.println("please input two paremeter!"); System.exit(0); } String filePath = args[0]; String phantomJsPath = args[1]; DesiredCapabilities cap = DesiredCapabilities.phantomjs(); cap.setCapability( PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] { // "--webdriver-loglevel=DEBUG", // "--proxy=org.openqa.grid.selenium.proxy.DefaultRemoteProxy", }); cap.setCapability( PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", "zh_CN"); // cap.setCapability("phantomjs.page.settings.userAgent","Mozilla/5.0 (Macintosh; Intel Mac OS X // 10.9; rv:25.0) Gecko/20100101 Firefox/25.0"); // "C:\\Users\\Administrator\\Desktop\\phantomjs-2.0.0-windows\\bin\\phantomjs.exe" cap.setCapability("phantomjs.binary.path", phantomJsPath); cap.setJavascriptEnabled(true); driver = new PhantomJSDriver(cap); WebDriverWait wait = null; wait = new WebDriverWait(driver, 60); driver.get(URL); /*try { Thread.currentThread().sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); }*/ // screenShot((TakesScreenshot) driver, "/home/admin/"+"mo9"+c+".png"); List<WebElement> nextElement = null; ArrayList<String> credits = new ArrayList<String>(); int prePage = 1; int curPage = c; BufferedWriter br = null; File f = new File(filePath); try { br = new BufferedWriter(new FileWriter(f, true)); br.write("mo9账号,真实姓名,身份证号,欠款金额,逾期天数"); br.write("\r\n"); } catch (IOException e1) { e1.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } while (!isLast) { List<WebElement> elements = null; try { elements = wait.until( ExpectedConditions.visibilityOfAllElementsLocatedBy( By.cssSelector("div.faith-list>dl.fs12"))); } catch (Exception e) { e.printStackTrace(); driver.close(); driver.quit(); while (elements == null) { try { Thread.currentThread().sleep(720000); // c=((curPage/15)*15)+1; // curPage=c; driver = new PhantomJSDriver(cap); // driver=new FirefoxDriver(binary,profile); wait = new WebDriverWait(driver, 60); driver.get("https://www.mo9.com/creditCenter/p/" + curPage); elements = wait.until( ExpectedConditions.visibilityOfAllElementsLocatedBy( By.cssSelector("div.faith-list>dl.fs12"))); } catch (Exception e1) { e1.printStackTrace(); } } } System.out.println(curPage); for (WebElement element : elements) { StringBuffer sb = new StringBuffer(); String acount = element.findElement(By.cssSelector("div.faith-list>dl.fs12>dt.row01")).getText(); String name = element.findElement(By.cssSelector("div.faith-list>dl.fs12>dd.row02")).getText(); String certiCard = element.findElement(By.cssSelector("div.faith-list>dl.fs12>dd.row03")).getText(); String debt = element.findElement(By.cssSelector("div.faith-list>dl.fs12>dd.row04")).getText(); String overDue = element.findElement(By.cssSelector("div.faith-list>dl.fs12>dd.row05")).getText(); sb.append(acount + "," + name + "," + certiCard + "," + debt + "," + overDue); credits.add(sb.toString()); } nextElement = driver.findElements(By.cssSelector("li>a.next")); if (credits.size() % 150 == 0 || nextElement.size() == 0) { try { br = new BufferedWriter(new FileWriter(f, true)); for (String str : credits) { br.write(str); br.write("\r\n"); } credits.clear(); } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } try { // Random r=new Random(100); // int n=r.nextInt(90); Thread.currentThread().sleep(20000); } catch (InterruptedException e) { e.printStackTrace(); } } if (nextElement.size() == 0) { isLast = true; } else { nextElement.get(0).click(); curPage++; try { Thread.currentThread().sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } } }