当我想运行这个程序而不是作为应用程序运行时,它将显示为“作为配置运行”。为什么会这样问
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了当我想运行这个程序而不是作为应用程序运行时,它将显示为“作为配置运行”。为什么会这样问相关的知识,希望对你有一定的参考价值。
我是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...
}
}
用户名似乎无效,但我相信你会管理。
以上是关于当我想运行这个程序而不是作为应用程序运行时,它将显示为“作为配置运行”。为什么会这样问的主要内容,如果未能解决你的问题,请参考以下文章
为啥当我使用变量存储数值结果而不是重新计算时,C++ 程序运行速度较慢?