当我想运行该程序而不是作为应用程序运行时,它将显示为“以配置形式运行”。为什么会这样问

时间:2018-09-03 06:34:02

标签: java selenium webdriver

我对硒部分很陌生,请检查此代码,以确保在不运行时运行此应用程序。而不是运行它将要求像以配置方式运行。

package com.shiftwizard.application;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Login {
    public WebDriver driver;
    public void positive()
    {
       System.setProperty("webdriver.chrome.driver", "D:\\prasanth softwares\\chromedriver_win32\\chromedriver.exe");
       WebDriver driver = new ChromeDriver();
       driver.get("https://devtest-new.myshiftwizard.com");
       driver.findElement(By.name("txtUserName")).sendKeys("cs@shiftwizard.com");
       driver.findElement(By.name("txtPassword")).sendKeys("P@ssword!1");
       driver.findElement(By.name("btnLogin1")).click();
    }
    public void negitive()
    {
        System.setProperty("webdriver.chrome.driver", "D:\\prasanth softwares\\chromedriver_win32\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.findElement(By.name("txtUserName")).sendKeys("cs@shiftwizard.com");
        driver.findElement(By.name("txtPassword")).sendKeys("P@ssword1");
        driver.findElement(By.name("btnLogin1")).click();
        System.out.println(driver.findElement(By.id("reqPass")));
    }
    public void close()
    {
        driver.close();
    }

}

这是我要运行此应用程序时的代码,就像运行以java应用程序形式列出的配置一样。

1 个答案:

答案 0 :(得分:0)

尝试一下:

// set you package name here
package Prabha;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Login {
    public static WebDriver driver;

    WebDriverWait wait5s = new WebDriverWait(driver,5);

    @BeforeClass
    public static void setUpClass() {

        // set your exe location here
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\pburgr\\Desktop\\chromedriver\\chromedriver.exe");

        ChromeOptions options = new ChromeOptions();

        // set your profile folder here or remove this line
        options.addArguments("user-data-dir=C:\\Users\\pburgr\\AppData\\Local\\Google\\Chrome\\User Data");

        driver = new ChromeDriver(options);
        driver.manage().window().maximize();

    }

    @Before
    public void setUp() {}

    @After
    public void tearDown() {}

    @AfterClass
    public static void tearDownClass() {driver.close();driver.quit();}

    @Test
    public void login() throws InterruptedException {

        // calling method "positive", the method "negative" still unused in this class
        positive();

    }

    public void positive() throws InterruptedException {
        driver.get("https://devtest-new.myshiftwizard.com");

        // wait 5 seconds to load the page
        wait5s.until(ExpectedConditions.elementToBeClickable(By.name("txtUserName"))).sendKeys("cs@shiftwizard.com");

        driver.findElement(By.name("txtPassword")).sendKeys("P@ssword!1");
        driver.findElement(By.name("btnLogin1")).click();
        Thread.sleep(5000);
        // to be continued...
    }

    public void negative() throws InterruptedException {
        driver.get("https://devtest-new.myshiftwizard.com");

        // wait 5 seconds to load the page
        wait5s.until(ExpectedConditions.elementToBeClickable(By.name("txtUserName"))).sendKeys("cs@shiftwizard.com");

        driver.findElement(By.name("txtPassword")).sendKeys("intentionally_wrong_password");
        driver.findElement(By.name("btnLogin1")).click();
        Thread.sleep(5000);
        // to be continued...
    }
}

该用户名似乎无效,但我相信您可以管理。