I'm using the code below. Test with priority 1 is executed successfully, but the code written under @test
with priority 2 is not execution.
Basically, webdriver is passing to another test. If I write all the code under the first test, it is executed successfully.
import javax.swing.plaf.basic.BasicTabbedPaneUI.TabSelectionHandler;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
import org.testng.asserts.*;
public class NonVodafone_TestNG
{
public static WebDriver driver;
public static WebDriverWait wait;
@Test(priority=1)
public void AuthorizeURL() throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\SinghA28\\Documents\\Abhimanyu_Office_Backup\\Softwares\\chromedriver_win32\\chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://dev.id.vodafone.com/mockup/");
//Generating Authorize URL
driver.findElement(By.id("env_idp")).sendKeys("PreProd");
driver.findElement(By.id("opco")).sendKeys("NV");
driver.findElement(By.id("btn_debug_url")).click();
driver.get(driver.findElement(By.id("txt_url")).getAttribute("value"));
Thread.sleep(5000);
driver.findElement(By.id("button")).click();
}
@Test(priority=2)
public void LandingPage()
{
//Assert.assertEquals(true, driver.findElement(By.xpath("//*[@id='form']/div[1]/div[1]/label")).isDisplayed());
System.out.println(driver.getCurrentUrl());
}
}
At AuthorizeURL()
, you declare a new variable ChromeDriver driver
in method's scope. You have to assign it to the class property WebDriver driver
.
@Test(priority=1)
public void AuthorizeURL() throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\SinghA28\\Documents\\Abhimanyu_Office_Backup\\Softwares\\chromedriver_win32\\chromedriver.exe");
NonVodafone_TestNG.driver = new ChromeDriver(); // <-- HERE
As driver reference variable is already declared you just need to call it.Change the code
ChromeDriver driver = new ChromeDriver();
To
driver = new ChromeDriver();
Hope it will help you :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.