在selenium webdriver中为从excel加载的多个URL创建循环

时间:2018-05-03 08:34:54

标签: java selenium testing selenium-webdriver automation

我有大约500个不同页面的URL,我需要创建一个循环来按顺序打开这个URL并在所有页面中执行相同的操作。 (即打开第一个URL并执行某些操作,然后打开第二个URL并执行相同的操作。

这是我的代码:

public class LoadPages {

  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();
  public static final String Path_TestData = "D://WorkSpace/myproject/src/utility/";
  public static final String File_TestData = "TestData.xlsx";


  @Before
  public void setUp() throws Exception {
ExcelUtils.setExcelFile(Constant.Path_TestData + Constant.File_TestData,"Sheet1");
   System.setProperty("webdriver.chrome.driver",
C://Users/Admin/Downloads/chromedriver_win32/chromedriver.exe); 
  driver = new  ChromeDriver();

 baseUrl = "https://3ddiagnostix.com/newcp/?task=22&subID=";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.manage().window().maximize();
 }

  @Test
  public void testUntitledTestCase() throws Exception {
String URL1 = ExcelUtils.getCellData(1, 2);
driver.get(baseUrl);
    driver.findElement(By.name("username")).click();
    driver.findElement(By.name("username")).clear();
    driver.findElement(By.name("username")).sendKeys(UserName);
    driver.findElement(By.name("password")).click();
    driver.findElement(By.name("password")).clear();
    driver.findElement(By.name("password")).sendKeys(Password);
    driver.findElement(By.xpath("//*[@id='contentDiv']/form/table/tbody/tr[4]/td[4]/input")).click();
    driver.get(baseUrl + URL2);
    Thread.sleep(2000);
    JavascriptExecutor jse = (JavascriptExecutor)driver;
    jse.executeScript("scroll(0,50)");
    new Select(driver.findElement(By.id("DSO"))).selectByVisibleText("2077: 3DDX Sample");
    driver.findElement(By.xpath("//option[@value='2077']")).click();
    Thread.sleep(2000);
    jse.executeScript("window.scrollTo(0, document.body.scrollHeight)");
    new Select(driver.findElement(By.id("DSO"))).selectByVisibleText("30633: SmileSource");
    driver.findElement(By.xpath("//option[@value='30633']")).click();
    driver.findElement(By.id("btnUpdate")).click();

0 个答案:

没有答案