私は過去にこの方法を使用しましたが、最近はセレンをあまり使用していません。このテストをセットアップして、複数のケースを順番に実行しようとしています。
これが私のコードです
import org.junit.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import java.time.Duration;
public class TotalAutomatation {
static WebDriver driver;
@BeforeClass public static void setup() throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\con15096\\snow_demo\\autotile\\drivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://nk.okta.com/login/login.htmfromURI=%2Fapp%2Fservicenow_app2%2Fexkbcm77encfzK3a80x7%2Fsso%2Fsaml%3FSAMLRequest%3DnVJdb5swFP0ryO9gMGkhVojEEk2L1nWoyfqwl8mBS2vF2MzX0Ky%252FfsTJ1O5hVbVH2%252Beej3u8QNEp1vNycI%252F6Dn4OgC44dkojP78UZLCaG4ESuRYdIHc135ZfbjiLYt5b40xtFAlKRLBOGr0yGocO7BbsKGv4dndTkEfneuSUYi%252BtdEJaJTVgA2OEZ1SozVNUm45qMfbiAaLGkGA9eZFanEhfKPQhMgcnPFj0Pb0QTPM%252FpiOjcDzs6y7LQNft8%252BdU5PExo4iGnuKQ4KOxNfiwBWmFQiDBZl2Q7e2qnWe1SK%252FZ1fwaGtam6TxncTtvr6DJ9yzJJiBWAlGO8DKKOMBGoxPaFYTFSR7GecjSXRzz2YzPkihm6XcSVJc1fZC6kfrh7Z3uzyDkn3a7Kqy%252BbneeYJQN2NsJ%252Fb%252FrvAeLfpWTCFkufL3cJ7CvG3%252FbnPhTM1m%252B28WCvta6KPf8lGWzroyS9a%252BgVMo8rSwIN%252BVzdgBfVSfcv%252B0kUeJvZBO2HsqhE1KVTWMBkdDlRffvz738DQ%253D%253D%26RelayState%3Dhttps%253A%252F%252Fspiritairlinesdev.service-now.com%252Fsolveit%253Fid%253Dsolveit_dept_dev");
Thread.sleep(1000);
driver.findElement(By.id("okta-signin-username")).sendKeys("username");
Thread.sleep(1500);
driver.findElement(By.id("okta-signin-password")).sendKeys("password");
Thread.sleep(1000);
driver.findElement(By.id("okta-signin-submit")).click();
Thread.sleep(1000);
driver.get("https://spiritairlinesdev.service-now.com/solveit");
}
@Test public void getFirstTile1() throws InterruptedException {
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@id=\"xd150fd31cb10020000f8d856634c9ce6\"]/li[1]/a")).click();
Thread.sleep(6000);
Select dropList = new Select(driver.findElement(By.id("edit_tile_level")));
dropList.selectByVisibleText("FlightOPS/ Inflight");
Thread.sleep(1500);
dropList.selectByVisibleText("Submit a New Request");
Thread.sleep(1500);
dropList.selectByVisibleText("System Access Request");
Thread.sleep(2000);
WebElement TemplateCard = driver.findElement(By.xpath("//*[@id=\"template_color\"]"));
WebElement card1= driver.findElement(By.xpath("//*[@id=\"02844eecdb486700433c38ff9d961914_color\"]"));
new Actions(driver)
.moveToElement(card1)
.pause(Duration.ofSeconds(1))
.clickAndHold(card1)
.pause(Duration.ofSeconds(1))
.moveToElement(TemplateCard)
.pause(Duration.ofSeconds(1))
.release().perform();
Thread.sleep(2000);
System.out.println("I have the first tile");
driver.findElement(By.id("previous_parent")).click();
Thread.sleep(1500);
driver.findElement(By.id("previous_parent")).click();
Thread.sleep(1500);
driver.findElement(By.id("previous_parent")).click();
Thread.sleep(1500);
dropList.selectByVisibleText("Airport Stations");
Thread.sleep(1500);
dropList.selectByVisibleText("Submit a New Request");
Thread.sleep(2000);
dropList.selectByVisibleText("System Access Request");
Thread.sleep(2000);
driver.findElement(By.id("save_new_tile")).click();
}
@AfterClass public static void closeWindow() throws InterruptedException {
Thread.sleep(1500);
driver.close();
}
}
@BeforeTestケースを実行しますが、最初の@Testに入ろうとすると失敗します
@BeforeClassの後でなぜ壊れているのか理解できません。
と
WebDriver driver = new FirefoxDriver();
メソッドローカル変数を作成します。したがって、静的フィールドが書き込まれることはありません。
削除WebDriver
するだけで、実際に静的フィールドにアクセスできます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加