アレイとして試験内のデータプロバイダエレメントの搾取、TestNGのを使用して

moadのhamouch:

私はセレンを作成したTestNGのwebdriverを自動化programeグラブデータはExcelシートをfomeフィルのためのいくつかのフィールドを、それらを使用していくつかのタスクを実行しています、

私は仕事がハードコーディングされている場合、正常に実行されるコードを書いたが、私はコーディングや繰り返しの内部に多くのハード避けたいので、@test私は@dataProvider要素をexploiteしたい配列リストを噴射させ、

これはコードです

package com.mycompany.app;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WindowType;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.excelreader.utility.getDataUtil;

public class testTab2 {
    static WebDriver driver;


    @BeforeTest
    public void beforeTest() 
    {
        System.setProperty("webdriver.chrome.driver", "C:\\Browsers drivers\\chromedriver.exe");
        driver = new ChromeDriver();

        driver.get("https://kdp.amazon.com/en_US/title-setup/paperback/new/details?ref_=kdp_BS_D_cr_ti");
        driver.findElement(By.xpath("//*[@id='ap_email']")).sendKeys("email");
        driver.findElement(By.xpath("//*[@id=\'ap_password\']")).sendKeys("password");
        driver.findElement(By.xpath("//*[@id=\"signInSubmit\"]")).click();
    }

    @BeforeMethod
    public void newTab() 
    {
        driver.switchTo().newWindow(WindowType.TAB);
        driver.get("https://kdp.amazon.com/en_US/title-setup/paperback/new/details?ref_=kdp_BS_D_cr_ti");

    }

    @Test(dataProvider = "getTestData")
    protected static void testAmazon1(String innerPath, String coverPath, String book_Title, String subtitle,
              String f_Name, String l_Name, String Description, String keyword1, String keyword2, 
              String keyword3, String keyword4, String keyword5, String keyword6, String keyword7, 
              String category_1, String category_2, String step_1, String step_2, String step_3, 
              String step_4, String step_5, String step_6, String step_7, String step_a, String step_b, 
              String step_c, String step_d, String step_e, String step_f, String step_g, String step_1final,String step_2final) throws Exception 
    {
        //driver = new ChromeDriver();
        Thread.sleep(4000);


        driver.findElement(By.xpath("//button[@id='data-print-book-categories-button-proto-announce']")).click();
        Thread.sleep(2000);



        String[] category_A = new String [7];

        category_A [0] = step_1;
        category_A [1] = step_2;
        category_A [2] = step_3;
        category_A [3] = step_4;
        category_A [4] = step_5;
        category_A [5] = step_6;
        category_A [6] = step_7;

        int i = 0;
        int index=0;
        while (i<=6) {
            if (category_A [i] != "kk") {
                i++;
            } else {
                index=i;
                System.out.println(index);
                break;
            }
        }

        for (int j=0; j<=index-2 ; j++) {

            String expand = driver.findElement(By.xpath("//div[@id='icon-" + category_A [j] + "']")).getAttribute("class");
            System.out.println("expand befor execution is: "+ expand);

            String icon_plus = "icon expand-icon";
            if(expand.equals(icon_plus)) {
                driver.findElement(By.xpath("//div[@id='icon-" + category_A [j] + "']")).click();}
                     else {
                        System.out.println(category_A [j] + " is expanded");
                    }
        }
        driver.findElement(By.xpath("//input[contains(@id,'"+ step_1final +"')]")).click();
        System.out.println("the following checkbox :" + step_1final + "is checked");

    }



      @DataProvider(parallel = false)
      public Iterator<Object[]> getTestData() {
          ArrayList<Object[]> testData = getDataUtil.getDataFromExcel();
          return testData.iterator();

      }

}

しかし、このプログラムは、それが配列に到達するまで実行し続け、それが私にこのメッセージを表示します。

出力

Starting ChromeDriver 79.0.3945.36 (XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-refs/branch-heads/XXXX@{#XXX}) on port XXXXX
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
janv. 27, 2020 5:30:51 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C

いずれかのソリューションを持っている場合、私はこの問題を解決する必要があります。どうもありがとうございました。

moadのhamouch:

私はちょうどそれを置き換えるif文

 if (category_A [i] != "kk") {

このwhith

 String breaker = "kk"
 if ( !category_A [i].contentEquals(breaker)) {

それは動作しますが、私はまだ理由が、その作業を知っているし、あなたの助けに感謝いけません。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=362352&siteId=1