I've installed Gecko driver but still getting an error - java

I've installed the Gecko driver because i was getting this error : "java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property;"
But after applying the code still i'm getting error for Gecko driver.
Below is my complete code. please let me know what I'm missing.
public class Pawan {
public static WebDriver driver;
public static void main(String[] args){
System.setProperty("webdriver.firefox.marionette","C:\\Users\\Lalit-pc\\Desktop\\geckodriver-v0.21.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
}
#Test
public void test() {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com/");
driver.findElement(By.linkText("Find a Physician")).click();
driver.findElement(By.id("searchZip")).sendKeys("32806");
driver.findElement(By.linkText("Mile Radius")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
driver.findElement(By.linkText("20")).click();
driver.findElement(By.linkText("Specialty")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
driver.findElement(By.linkText("Anesthesiology")).click();
driver.findElement(By.cssSelector("input[type='submit'][value='Search Now']")).click();
String str= driver.findElement(By.xpath(".//*[#id='finderListView']/div[3]/div[1]/div/div[1]/p")).getText();
if("Anesthesiology".equals(str))
System.out.println("Physician Search Successful");
else
System.out.println("Physician Search NOT Successful");
driver.findElement(By.linkText("Browse Locations")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
driver.findElement(By.xpath(".//*[#id='sidebarMenu']/div[1]/form/div/input")).sendKeys("32806");
driver.findElement(By.xpath(".//*[#id='sidebarMenu']/div[1]/form/input")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
driver.findElement(By.xpath(".//*[#id='sidebarMenu']/div[2]/section/div/ul/li[1]/a")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
WebElement divElement = driver.findElement(By.xpath(".//*[#id='overflow-autoScroll']/li[1]/ul/li/a/div[2]/span[3]"));
String stri = divElement.getText();
if(stri.contains("32806"))
System.out.println("Location Search successful");
else
System.out.println("Location Search not successful");
driver.findElement(By.xpath("html/body/header/div[1]/div[2]/a[3]")).click();
driver.findElement(By.linkText("Health Topics")).click();
try{
Thread.sleep(6000);
}catch (InterruptedException ie1) {
ie1.printStackTrace();
}
driver.findElement(By.linkText("Diabetes")).click();
WebElement divElementtwo = driver.findElement(By.xpath("html/body/div[4]/div/div[1]/div[1]/h2"));
String strn = divElementtwo.getText();
if(strn.contains("Diabetes"))
System.out.println("Blog Search successful");
else
System.out.println("Blog Search not successful");
}
}

To verify gecko driver is compatible with your current firefox & selenium version, do the following:
Keep downloaded gecko driver at System32 if you are on Windows OS & /usr/local/bin if you are on Mac OSX
Run the Selenium Standalone server by this command: java -jar selenium-server-standalone-3.13.0.jar
Open this url in Firefox browser: http://localhost:4444/wd/hub
Create Session and Select Firefox browser
If browser starts then there is no issue with the compatibility of geckodriver with Firefox & Selenium version.

small setup change requied: (latest firefox browser)
public class Pawan {
public static WebDriver driver;
#BeforeClass
public static setup() {
System.setProperty("webdriver.gecko.driver","C:\\Users\\Lalit-pc\\Desktop\\geckodriver-v0.21.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
}
// Urs test here

JUnit uses a different main entry point than the public static void main(String[] args) method you've defined there, so if you execute the tests, System#setProperty won't be executed.
To add the system property once for all tests in the class, you need to define a #BeforeClass method:
public class Pawan {
public static WebDriver driver;
#BeforeClass
static void init() {
System.setProperty("webdriver.firefox.marionette","C:\\Users\\Lalit-pc\\Desktop\\geckodriver-v0.21.0-win64\\geckodriver.exe");
}
//test cases here...
}
Now, for development purposes, I recommend setting this variable as a constant accessible by your PATH environment variable (OS dependent) rather than setting it as a system property.

You can also define geckodriver in #Test if you do not want #BeforeClass annotation :
#Test
public void test() {
System.setProperty("webdriver.firefox.marionette","C:\\Users\\Lalit-pc\\Desktop\\geckodriver-v0.21.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com/");
This will also work:)

Related

Running Selenium on jenkins takes my local chromedriver

I'm trying to test our website with selenium via Jenkins so that everyday every feature gets tested.
The problem is that Jenkins fails because he is trying to get the chromedriver with my local path but there is no local path.
The error message:
[ERROR] main(at.s2gplus.selenium.TestPromoteToAdmin) Time elapsed:
0.006 s <<< FAILURE! java.lang.IllegalStateException: The driver executable does not exist:
/opt/jenkins/workspace/buzzApi/C:/Users/mario/AppData/Local/Google/Chrome/Application/chromedriver.exe
at
at.s2gplus.selenium.TestPromoteToAdmin.main(TestPromoteToAdmin.java:36)
The code:
public class TestPromoteToAdmin {
WebDriver driver = new ChromeDriver();
#Test
public void main() {
driver.get("https://192.168.1.45:8080/");
WebDriverWait wait = new WebDriverWait(driver, 90);
driver.manage().window().maximize();
driver.findElement(By.id("details-button")).click();
driver.findElement(By.id("proceed-link")).click();
driver.findElement(By.id("home-open-sign-in")).click();
driver.findElement(By.id("login-username")).sendKeys("tester");
driver.findElement(By.id("login-password")).sendKeys("wurst01");
driver.findElement(By.id("login-action")).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("left-menu-room-title-add-action"))).click();
driver.findElement(By.id("create-room-name-input")).sendKeys("Selenium Admin test");
driver.findElement(By.id("create-room-description-input")).sendKeys("Selenium Test");
driver.findElement(By.id("create-room-save")).click();
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement roomToClick = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(text(), 'Selenium Admin test')]")));
js.executeScript("arguments[0].scrollIntoView();", roomToClick);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wait.until(ExpectedConditions.elementToBeClickable(roomToClick)).click();
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(#id, 'left-roomlist-settingsicon')]"))).click();
WebElement addMemberBtn = wait.until(ExpectedConditions.elementToBeClickable(By.id("room-settings-add-user")));
addMemberBtn.click();
WebElement checkBox = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("label[for='990bd6a8-62af-48c5-89a5-33019483c91f'")));//("cb732433-eae9-434b-96da-b4d5a499208c"));
checkBox.click();
WebElement addBtn = driver.findElement(By.id("room-settings-add-button"));
addBtn.click();
WebElement saveUserBtn = driver.findElement(By.id("room-settings-save"));
saveUserBtn.click();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(#id, 'left-roomlist-settingsicon')]"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("general-menu-list-item-settings"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("room-settings-context-change-role-to-moderator"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("general-menu-list-item-settings"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("room-settings-context-change-role-to-admin"))).click();
driver.findElement(By.id("room-settings-save")).click();
driver.findElement(By.id("top-logout")).click();
driver.findElement(By.id("home-open-sign-in")).click();
driver.findElement(By.id("login-username")).sendKeys("tester01");
driver.findElement(By.id("login-password")).sendKeys("wurst02");
driver.findElement(By.id("login-action")).click();
roomToClick = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(text(), 'Selenium Admin test')]")));
js.executeScript("arguments[0].scrollIntoView();", roomToClick);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wait.until(ExpectedConditions.elementToBeClickable(roomToClick)).click();
WebElement roomAdmin = driver.findElement(By.xpath("//span[contains(text(), 'Selenium Admin test')]"));
String room = roomAdmin.getText();
assertTrue(room, true);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(#id, 'left-roomlist-settingsicon')]"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("meeting-settings-open-close-room-modal"))).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("meeting-settings-close-room-confirm"))).click();
}
#BeforeTest
public void beforeTest() {
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
options.setAcceptInsecureCerts(true);
driver = new ChromeDriver(options);
}
#AfterTest
public void afterTest() {
driver.quit();
}
}
line 36 is above driver.get("https://192.168.1.45:8080/"); but I have deleted it a long time ago
Install Selenium Grid Plugin in the Jenkins, use below code for node setup. Update the versions of selenium server standalone jar and browser versions in the below code.
java -jar selenium-server-standalone-x.xx.x.jar -
Dwebdriver.chrome.driver="C:\yourpath\chromedriver.exe" -role node -hub
http://localhost:4444/grid/register -browser "browserName=internet
explorer,version=xx,platform=WINDOWS" -browser
"browserName=chrome,version=xx,platform=WINDOWS"
Please update below line of code for starting
WebDriver driver = null;
#Test
public void main() {
System.setProperty("webdriver.chrome.driver","E:\\drivers\\ChromeDrivers\\85\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://192.168.1.45:8080/");
WebDriverWait wait = new WebDriverWait(driver, 90);
driver.manage().window().maximize(); ```

Getting java.lang.NullPointerException in POM uisng page Factory

I've posted below some sample code which I've done so far and I'm getting an Exception java.lang.NullPointerException.
Base Class:
public class TestBase {
public static WebDriver driver= null;
#BeforeSuite
public void initialize(){
System.setProperty("webdriver.chrome.driver","...chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("abcd.com");
}
#AfterSuite
public void TearDownTest()
{
TestBase.driver.quit();
}
}
Login Page:
public class LoginPage {
WebDriver driver;
public LoginPage(WebDriver driver)
{
this.driver= driver;
}
#FindBy(how=How.XPATH, using="//*[#id='email_id']") WebElement EmailTextBox;
#FindBy(how=How.XPATH, using="//*[#id='password']")WebElement PassworTextBox;
#FindBy(how=How.XPATH, using="//*[#id='frm_login']/div[4]/input") WebElement LoginButton;
public void setemail(String strmail)
{
EmailTextBox.sendKeys(strmail);
}
public void setpwd(String strpwd)
{
try
{
PassworTextBox.sendKeys(strpwd);
}
catch (TimeoutException e)
{
System.out.println("Time out exception " + e);
}
catch (ElementNotSelectableException e) {
System.out.println("Element not selectable exception " + e);
} catch (NoSuchElementException e) {
System.out.println("No such element found " + e);
} catch (ElementNotVisibleException e) {
e.printStackTrace();
} catch (Exception e) {
System.out.println("Something Wrong " + e);
}
}
public void ClickLoginBtn()
{
LoginButton.click();
}
}
LoginTest class:
public class LoginTest extends TestBase{
#Test
public void init()
{
System.out.println("In the init method");
LoginPage lg=PageFactory.initElements(driver, LoginPage.class);
lg.setpwd("123123");
lg.setemail("abc#gmail.com");
lg.ClickLoginBtn();
}
}
I am getting the NullPointerException while setting the username and password. Could you please help me?
I am new to the POM with PageFactory so I dont have any idea How to resolve it but If anyone can help me with that it would be big help to me.
You shouldn't initialise the WebDriver instance i.e. driver twice as follows:
public static WebDriver driver= null;
and
WebDriver driver=new ChromeDriver();
Keep the global declaration as:
public static WebDriver driver= null;
And channge the line as:
driver=new ChromeDriver();
Try to add a timeout after driver.get("abcd.com"); to be sure page has finished to load, and can find WebElements defining EmailTextBox and PassworTextBox.
Or use a WebDriverWait like this
new WebDriverWait(driver, 10))
.until(ExpectedConditions.visibilityOf(By.id("someid")));
I hope you have initialized the page factory elements like so
public LoginPage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
In your Test class,
I would place
LoginPage lg = new LoginPage(driver);
Read more here:
https://www.seleniumeasy.com/selenium-tutorials/page-factory-pattern-in-selenium-webdriver

Get OS system and relative path to a folder in java

I write my test on my local Windows, and I create webdriver like this:
#BeforeMethod
#Parameters("browser")
public void setUp(String browser) throws Exception {
if (browser.equalsIgnoreCase("chrome")) {
System.out.println("Chrome test starting ...");
System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver_win.exe");
webDriver = new ChromeDriver();
}
else {
throw new Exception("Browser is not supported");
}
For the setProperty, I use a hard path to Chrome Driver, but I would like change the path to relative by checking the OS to use appropriate driver for Windows and Mac. Can someone give me a hint. Thanks
By using config property file you can get both browser type and chrome driver location.
you can create one folder in your work space with the name Drivers and paste your chrome driver
Below is config.properties file
browserType=Chrome
ChromeDriver = Drivers/chromedriver.exe
Below is the code to run chrome driver on different operating systems
String os = System.getProperty("os.name");
public String currentBrowser;
if(CONFIG.getProperty("browserType").contains(","))
{
data=currentBrowser;
}
if (os.contains("Windows"))
{
else if (data.equals("Chrome")) {
APP_LOGS.debug("Chrome Browser Opening Method Start");
DesiredCapabilities capability = DesiredCapabilities.chrome();
// To Accept SSL certificate
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
System.setProperty("webdriver.chrome.driver",
CONFIG.getProperty("ChromeDriver"));
Thread.sleep(10000);
driver = new ChromeDriver();
driver.manage().window().maximize();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
long
implicitWaitTime=Long.parseLong(CONFIG.getProperty("implicitwait"));
driver.manage().timeouts().implicitlyWait(implicitWaitTime,
TimeUnit.SECONDS);
driver.manage().window().maximize();
}
return os;
}
Why are you putting chromedriver in src? Your jar will be needing that folders while running.
Source Code and the Binary files should not be put together in production environment.
Create a libs folder and put all types of chromedrivers in it. With slight change in name.
chromedriver_mac
chromedriver_win
chromedriver_linux
Code
#BeforeMethod
#Parameters("browser")
public void setUp(String browser) throws Exception {
if (browser.equalsIgnoreCase("chrome")) {
System.out.println("Chrome test starting ...");
System.setProperty("webdriver.chrome.driver", getChromeDriverPath());
webDriver = new ChromeDriver();
}
else {
throw new Exception("Browser is not supported");
}
}
public static String getChromeDriverPath() {
String OS = System.getProperty("os.name");
if (OS.contains("Window")) {
return "libs/chromedriver_win"
} else if (OS.contains("Mac")) {
return "libs/chromedriver_mac"
} else {
return "libs/chromedriver_linux"
}
}
The below code should work,
if(type.equalsIgnoreCase("CHROME"))
{
log.info("Executing Operating System = "+System.getProperty("os.name").toLowerCase());
String osname =System.getProperty("os.name");
if(osname.toLowerCase().contains("windows")) System.setProperty("webdriver.chrome.driver","src/test/resources/chromedriver.exe" );
else if(osname.toLowerCase().contains("linux"))
{
String filepathtoset = System.getProperty("user.dir")+"/src/test/resources/chromedriver";
System.setProperty("webdriver.chrome.driver",filepathtoset );
}
else System.setProperty("webdriver.chrome.driver","src/test/resources/chromedrivermac");

Selenium webdriver : Multiple drivers

I have used 3 drivers firefox, chrome and IE for automated testing.
static WebDriver driver ;
public static void main(String args[]) {
try {
driver = new FirefoxDriver();
runTest(driver, "FireFox");
//Chrome
System.setProperty("webdriver.chrome.driver","E:/selinium_drivers/chromedriver.exe");
driver = new ChromeDriver();
runTest(driver, "Chrome");
//IE
System.setProperty("webdriver.ie.driver","E:/selinium_drivers/IEDriverServer.exe");
driver = new InternetExplorerDriver();
runTest(driver, "IE");
}
The problem is the second driver is starting before the first driver complete it's process. How can i stop second driver till the first driver finish it work.
public static void runTest(WebDriver driver, String browserName) {
try {
testLogin(driver);
testSignupC(driver);
testSignUpCLogin(driver);
driver.close();
} catch(Exception ex) {
//log stack trace
//Alter(test failed in browser name)
}
}
You didn't mention your WebDriver version; my comments are based on API 2.45.
First, you should call driver.quit() instead of close():
/**
* Close the current window, quitting the browser if it's the last window currently open.
*/
void close();
/**
* Quits this driver, closing every associated window.
*/
void quit();
Second, you should secure the driver shutdown in a finally block:
try {
testLogin(driver);
testSignupC(driver);
testSignUpCLogin(driver);
} catch(Exception ex) {
//log stack trace
//Alter(test failed in browser name)
} finally {
driver.quit();
}
Additionally, I would surround quit() with a try/catch on WebDriverException and set driver to null in order to prevent its reuse since the driver initialization (startClient(), startSession()...) is done in the constructor:
} finally {
try {
driver.quit();
catch (WebDriverException e) {
// log if useful else NO OP
}
driver = null;
}

How to run a test in testNG using Selenium WebDriver?

Currently working on Selenium WebDriver, Java and TestNG frame work.
Please give ideas about TestNG framework.
For example, i have a file test.java. I have written java code with
#BeforeTest , #Test, #AfterTest. while running the code each test is running and am getting how many test got passed and how many got failed.
But i want solution for the secnario:
I have two tabs called Default and Internal vs External
After clicking the default tab i want run many test for that particular tab, once those test executed then i need to click on the Internal vs External then i need to run all test belongs to that tab.
How can i get result in the TestNG frame work.
The following code:
public class OverviewAndEvolutionPR{
private static Logger Log = Logger.getLogger(OverviewAndEvolutionPR.class.getName());
private WebDriver driver;
private StringBuffer verificationErrors = new StringBuffer();
Properties p= new Properties();
public Selenium selenium;
//#BeforeMethod
#BeforeTest
public void Login() throws Exception {
driver = new FirefoxDriver();
try {
p.load(new FileInputStream("C:/Login.txt"));
} catch (Exception e) {
e.getMessage();
}
String url=p.getProperty("url");
DOMConfigurator.configure("src/log4j.xml");
Log.info("______________________________________________________________");
Log.info("Initializing Selenium...");
selenium = new DefaultSelenium("localhost", 4444, "*firefox",url);
Thread.sleep(5000);
Log.info("Selenium instance started");
try {
p.load(new FileInputStream("C:/Login.txt"));
} catch (Exception e) {
e.getMessage();
}
Log.info("Accessing Stored uid,pwd from the stored text file");
String uid=p.getProperty("loginUsername");
String pwd=p.getProperty("loginPassword");
Log.info("Retrieved uid pwd from the text file");
try
{
driver.get("https://test.com");//example i had given like this
}
catch(Exception e)
{
Reporter.log("network server is slow..check internet connection");
Log.info("Unable to open the website");
throw new Error("network server is slow..check internet connection");
}
performLogin(uid,pwd);
}
public void performLogin(String uid,String pwd) throws Exception
{
Log.info("Sign in to the OneReports website");
Thread.sleep(5000);
Log.info("Enter Username");
driver.findElement(By.id("loginUsername")).sendKeys(uid);
Log.info("Enter Password");
driver.findElement(By.id("loginPassword")).sendKeys(pwd);
//submit
Log.info("Submitting login details");
waitforElement(driver,120 , "//*[#id='submit']");
driver.findElement(By.id("submit")).submit();
Thread.sleep(6000);
Actions actions = new Actions(driver);
Log.info("Clicking on Reports link");
if(existsElement("reports")==true){
WebElement menuHoverLink = driver.findElement(By.id("reports"));
actions.moveToElement(menuHoverLink).perform();
Thread.sleep(6000);
}
else{
Log.info("element not present");
System.out.println("element not present -- so it entered the else loop");
}
Log.info("Clicking on Extranet link");
if(existsElement("extranet")==true){
WebElement menuHoverLink = driver.findElement(By.id("extranet"));
actions.moveToElement(menuHoverLink).perform();
Thread.sleep(6000);
}
else{
Log.info("element not present");
System.out.println("element not present -- so it entered the else loop");
}
Log.info("Clicking on PR link");
if(existsElement("ext-pr")==true){
WebElement menuHoverLink = driver.findElement(By.id("ext-pr"));
actions.moveToElement(menuHoverLink).perform();
Thread.sleep(6000);
}
else{
Log.info("element not present");
System.out.println("element not present -- so it entered the else loop");
}
Log.info("Clicking on Overview and Evolution PR link");
if(existsElement("ext-pr-backlog-evolution")==true){
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", driver.findElement(By.id("ext-pr-backlog-evolution") ));
Thread.sleep(6000);
}
else{
Log.info("element not present");
System.out.println("element not present -- so it entered the else loop");
}
}
//Filter selection-1
//This filter selection need to happen in Default tab
#Test()
public void Filterselection_1() throws Exception{
Log.info("Clicking on Visualization dropdown");
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById('visualizationId').style.display='block';");
Select select = new Select(driver.findElement(By.id("visualizationId")));
select.selectByVisibleText("Week");
Thread.sleep(6000);
Log.info("Clicking on Period dropdown");
JavascriptExecutor executor1 = (JavascriptExecutor)driver;
executor1.executeScript("document.getElementById('periodId').style.display='block';");
Select select1 = new Select(driver.findElement(By.id("periodId")));
select1.selectByVisibleText("Last 4 Weeks");
Thread.sleep(6000);
Log.info("Clicking on Type dropdown");
JavascriptExecutor executor2 = (JavascriptExecutor)driver;
executor2.executeScript("document.getElementById('classificationId').style.display='block';");
Select select2 = new Select(driver.findElement(By.id("classificationId")));
select2.selectByVisibleText("Customer PRs");
Thread.sleep(6000);
Log.info("Clicking on Apply Filter button");
driver.findElement(By.id("kpiFilterSubmit")).click();
}
//In the default tab many filter section i will have once it completed then i need to move to other tab and need to check the filter selection
//Filter selection-2
//It need to happen in the Internal vs External tab
#Test
public void Filterselection_2() throws Exception{
Log.info("Clicking Internal Vs External tab");
driver.findElement(By.linkText("Internal vs External")).click();
Thread.sleep(6000);
Log.info("Clicking on Visualization dropdown");
JavascriptExecutor executor3 = (JavascriptExecutor)driver;
executor3.executeScript("document.getElementById('visualizationId').style.display='block';");
Select select3 = new Select(driver.findElement(By.id("visualizationId")));
select3.selectByVisibleText("ICC");
Thread.sleep(6000);
Log.info("Clicking on Type dropdown");
JavascriptExecutor executor02 = (JavascriptExecutor)driver;
executor02.executeScript("document.getElementById('classificationId').style.display='block';");
Select select02 = new Select(driver.findElement(By.id("classificationId")));
select02.selectByVisibleText("Internal PRs");
Thread.sleep(6000);
Log.info("Clicking on topography dropdown");
JavascriptExecutor executor4= (JavascriptExecutor)driver;
executor4.executeScript("document.getElementById('topographyId').style.display='block';");
Select select4 = new Select(driver.findElement(By.id("topographyId")));
select4.selectByVisibleText("ICC");
Thread.sleep(6000);
Log.info("Clicking on Apply Filter button");
driver.findElement(By.id("kpiFilterSubmit")).click();
Thread.sleep(6000);
}
private boolean existsElement(String id) {
try {
driver.findElement(By.id(id));
} catch (Exception e) {
System.out.println("id is not present ");
return false;
}
return true;
}
private void waitforElement(WebDriver driver2, int i, String string) {
// TODO Auto-generated method stub
}
//#AfterMethod
#AfterTest
public void tearDown() throws Exception {
Log.info("Stopping Selenium...");
Log.info("______________________________________________________________");
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
Assert.fail(verificationErrorString);
}
}
}
Use the attribute dependsOnMethods, of #Test, to sequentialize your tests. You can read further about the annotations in TestNG at - TectNG Annotations.
So why don't you abstract those tests and than call it in your "Default" and "Internal vs External"? In you case I would use Page Objects
You can use Groups annotation in TestNG. Write all your required Test cases under Default tab, then add that test cases into one group as below
public class Test1 {
#Test(groups = { "functest", "checkintest" })
public void testMethod1() {
}
#Test(groups = {"functest", "checkintest"} )
public void testMethod2() {
}
#Test(groups = { "functest" })
public void testMethod3() {
}
}
And it will execute that particular group test cases, then it will execute another once group test cases are completed.
testng.xml
<test name="Test1">
<groups>
<run>
<include name="functest"/>
</run>
</groups>
<classes>
<class name="example1.Test1"/>
</classes>
</test>

Categories