0

我正在执行一个 selenium 测试脚本。但是我在导入 selenium 类文件和 chrome 驱动程序类时遇到了一个问题。我已将 selenium jar 文件引用到项目中。任何人都可以帮我解决这个问题。我是连同此一起提交代码:

package org.karmaloop.testcase;

import java.io.File;
import java.io.IOException;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.karmaloop.configuration.Testconfiguration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

@RunWith(BlockJUnit4ClassRunner.class)
public class testcase1 {

    private static ChromeDriverService srv;
    private WebDriver driver;

    @BeforeClass
    public static void StartServer() throws IOException {
        // Below file path to Chrome browser should be changed accordingly
        srv = new ChromeDriverService.Builder()
                .usingDriverExecutable(
                        new File("D:\\chromedriver\\chromedriver.exe"))
                .usingAnyFreePort().build();
        srv.start();
    }

    @AfterClass
    public static void tearDownAfterClass() throws Exception {
    }

    @Before()
    public void setUp() throws Exception {

        driver = new RemoteWebDriver(srv.getUrl(), DesiredCapabilities.chrome());
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void test() throws Exception {

        // Login();

        //ADD_TO_CART();

        Normal_Checkout();


        // fail("Not yet implemented");
    }

    private void Normal_Checkout() throws Exception {



    }

    private void ADD_TO_CART() throws Exception {

        driver.get(Testconfiguration.Applicationurl);

        driver.findElement(By.xpath(Testconfiguration.Homelogo)).click();

        Thread.sleep(4000);

        driver.findElement(By.xpath(Testconfiguration.Shopmens)).click();

        Thread.sleep(4000);

        driver.findElement(By.xpath(Testconfiguration.brands_button)).click();

        Thread.sleep(4000);

        System.out.println(true);

        driver.findElement(By.xpath(Testconfiguration.adidas)).click();

        Thread.sleep(2000);

        System.out.println(true);

        Thread.sleep(4000);

        driver.findElement(By.xpath(Testconfiguration.salesort)).click();

        Thread.sleep(8000);

        driver.findElement(By.xpath(Testconfiguration.salesort_Hightolow)).click();

        Thread.sleep(20000);

        System.out.println("passed");

        driver.findElement(By.xpath(Testconfiguration.salesort_firstproduct)).click();

        Thread.sleep(10000);

        driver.findElement(By.cssSelector(Testconfiguration.size_dropdown)).click();

        System.out.println("success");

        Thread.sleep(2000);

        System.out.println("success2");

        driver.findElement(By.xpath(Testconfiguration.select_size)).click();

        Thread.sleep(4000);

        driver.findElement(By.xpath(Testconfiguration.addtocart_button)).click();

        Thread.sleep(4000);


    }

    public void Login() throws Exception {

        driver.findElement(By.xpath(Testconfiguration.signin_button)).click();

        Thread.sleep(5000);

        driver.findElement(By.xpath(Testconfiguration.emailid_textbox)).sendKeys(Testconfiguration.login_username);

        Thread.sleep(5000);
        driver.findElement(By.xpath(Testconfiguration.password_textbox)).sendKeys(Testconfiguration.login_password);

        Thread.sleep(5000);

        driver.findElement(By.xpath(Testconfiguration.login_button)).click();

        Thread.sleep(5000);

    }

}
4

0 回答 0