Java 当我想运行这个程序而不是作为应用程序运行时,它会显示为;“以配置方式运行”;。为什么会这样问
我对selenium一节非常陌生,当我想以非运行状态运行此应用程序时,请检查这段代码。它不会运行它,而是像运行配置一样请求Java 当我想运行这个程序而不是作为应用程序运行时,它会显示为;“以配置方式运行”;。为什么会这样问,java,selenium,webdriver,Java,Selenium,Webdriver,我对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
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();
}
}
这是我的代码,当我想运行这个应用程序时,我得到了类似run as java应用程序的run as配置列表。试试这个:
// 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...
}
}
用户名似乎无效,但我相信你会处理的