jeudi 3 mai 2018

Create loop for multiple URLs loaded from excel in selenium webdriver

I have about 500 URLs for the different pages, I need to create a loop to open this urls in sequence and do the same actions in all pages. (i.e openeing the first URL and do some actions then open the second URL and do the same actions.

here is my code:

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();

Aucun commentaire:

Enregistrer un commentaire