簡體   English   中英

當我要運行此程序而不是作為應用程序運行時,它將顯示為“以配置形式運行”。 為什么會這樣問

[英]When i want to run this program instead of run as application it will shown like “run as configuration”. Why it will ask like this

我對selenium部分非常陌生,請檢查此代碼,以便在我不運行該應用程序時運行它。 如果不運行它,它將要求以配置方式運行。

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身份運行的應用程序列出的配置那樣運行。

嘗試這個:

// 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...
    }
}

用戶名似乎無效,但我相信您可以管理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM