I'm trying to type selenium in google and get all the title text of result in a notepad file. i want to get all available links on all the pages, till last page of search. but only 1st page's link i am getting. when i debug and run, it is working for some 10 pages.help me in this.
JAVA code:
public class weblink
{
public static void main(String[] args) throws IOException, InterruptedException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "E:\\disha.shah/myWork/eclipse/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.google.co.in/");
driver.findElement(By.id("lst-ib")).sendKeys("Selenium");
driver.findElement(By.id("_fZl")).click();
PrintStream ps = new PrintStream(new File(("E:\\disha1.txt")));
do
{
List<WebElement> findElements = driver.findElements(By.xpath("//*[#id='rso']//h3/a"));
for (WebElement webElement : findElements)
{
System.out.println("-" + webElement.getText()); // for title
//System.out.println(webElement.getAttribute("href")); // for links
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
System.setOut(ps);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
Thread.sleep(1000);
if(driver.findElement(By.linkText("Next")).isDisplayed()== true)
{
driver.findElement(By.linkText("Next")).click();
}
else
{
System.out.println("All Link is Covered");
}
}
while(driver.findElement(By.linkText("Next")).isDisplayed() );
{
//Thread.sleep(2000);
}
}
}
I've done some correction. the updated code is below.-
public static void main(String[] args) throws IOException, InterruptedException
{
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "D:/Application/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://www.google.co.in/");
driver.findElement(By.id("lst-ib")).sendKeys("Selenium");
driver.findElement(By.id("_fZl")).click();
Boolean nextButtonFlag = true;
// Create two separate file storing the result
PrintStream searchTitle = new PrintStream(new File(("D:\\Titles.txt")));
PrintStream searchLink = new PrintStream(new File(("D:\\Links.txt")));
do
{
List<WebElement> findElements = driver.findElements(By.xpath("//h3[#class='r']/a"));
for (WebElement element : findElements)
{
// Write all received links and title inn txt file
searchTitle.append(element.getText()+"\n");
searchLink.append(element.getAttribute("href")+"\n");
}
Thread.sleep(2000);
try
{
driver.findElement(By.linkText("Next")).click();
}
catch(Exception e)
{
// no more next button to navigate further link
nextButtonFlag=false;
}
Thread.sleep(2500);
}
while(nextButtonFlag);
System.out.println("Execution done");
searchTitle.close();
searchLink.close();
}
}
Related
using Java 17 and slenium 4.0
wait.until(ExpectedConditions.titleContains("BrowserStack"));
here is full code :
public class mainTestClass {
public static final String USERNAME = "myuser *****";
public static final String AUTOMATE_KEY = "my ke *****";
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "#hub-cloud.browserstack.com/wd/hub";
public static void main(String[] args) throws Exception {
Thread object1 = new Thread(new TestClass1());
object1.start();
Thread object2 = new Thread(new TestClass2());
object2.start();
Thread object3 = new Thread(new TestClass3());
object3.start();
}
public void executeTest(Hashtable<String, String> capsHashtable) {
String key;
DesiredCapabilities caps = new DesiredCapabilities();
// Iterate over the hashtable and set the capabilities
Set<String> keys = capsHashtable.keySet();
Iterator<String> itr = keys.iterator();
while (itr.hasNext()) {
key = itr.next();
caps.setCapability(key, capsHashtable.get(key));
}
WebDriver driver;
try {
driver = new RemoteWebDriver(new URL(URL), caps);
JavascriptExecutor jse = (JavascriptExecutor)driver;
// Searching for 'BrowserStack' on google.com
driver.get("https://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("BrowserStack");
element.submit();
// Setting the status of test as 'passed' or 'failed' based on the condition; if title of the web page contains 'BrowserStack'
WebDriverWait wait = new WebDriverWait(driver, 5);
try {
// wait.until(ExpectedConditions.titleContains("BrowserStack"));
jse.executeScript("browserstack_executor: {\"action\": \"setSessionStatus\", \"arguments\": {\"status\": \"passed\", \"reason\": \"Title matched!\"}}");
}
catch(Exception e) {
jse.executeScript("browserstack_executor: {\"action\": \"setSessionStatus\", \"arguments\": {\"status\":\"failed\", \"reason\": \"Title not matched\"}}");
}
System.out.println(driver.getTitle());
driver.quit();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
This is cause in Selenium 4.0.0 (Stable)
WebDriverWait which takes driver and timeoutInSeconds long, have been Deprecated
#Deprecated
public WebDriverWait(WebDriver driver, long timeoutInSeconds) {
this(driver, Duration.ofSeconds(timeoutInSeconds));
}
Fix:
Selenium devs have given this method instead
public WebDriverWait(WebDriver driver, Duration timeout) {
this(
driver,
timeout,
Duration.ofMillis(DEFAULT_SLEEP_TIMEOUT),
Clock.systemDefaultZone(),
Sleeper.SYSTEM_SLEEPER);
}
so your effective code will be :
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
try {
wait.until(ExpectedConditions.titleContains("BrowserStack"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
}
catch(Exception e) {
e.printStackTrace();
}
Trying to locate Radio Button inside iFrame but getting error as No Such Element found.
Tried switching to iFrame but still getting the same error. Not sure what am I missing. Tried couple of methods but did not get through. Not sure if my Xpath is wrong or way I use id to locate element is wrong. [Verified my Xpath in Developer tools but still getting the same error of No suh Element found]
Thank you in advance.
public class Sap_Demo {
WebDriver driver;
JavascriptExecutor jse;
public static void main(String[] args)
{
Sap_Demo demoObj = new Sap_Demo();
demoObj.invokeBrowser();
demoObj.initializeSAPFiory();
demoObj.forecastMD61();
}
public void invokeBrowser()
{
System.setProperty("webdriver.chrome.driver", "U:\\Research Paper\\Selenium\\Drivers\\Chrome\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
}
public void initializeSAPFiory()
{
try
{
Thread.sleep(1200);
driver.get("https://dijon.cob.csuchico.edu:8042/erp");
driver.findElement(By.id("USERNAME_FIELD-inner")).sendKeys("H4");
Thread.sleep(1200);
driver.findElement(By.id("PASSWORD_FIELD-inner")).sendKeys("Onsjhjsa1087");
Thread.sleep(1200);
driver.findElement(By.id("CLIENT_FIELD-inner")).clear();
Thread.sleep(1200);
driver.findElement(By.id("CLIENT_FIELD-inner")).sendKeys("485");
Thread.sleep(1200);
driver.findElement(By.xpath("//span[#class='sapMBtnContent sapMLabelBold sapUiSraDisplayBeforeLogin']")).click();
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void forecastMD61()
{
try {
driver.findElement(By.id("erpsim-tcode-btn-img")).click();
Thread.sleep(1200);
driver.findElement(By.id("TCode-input-inner")).sendKeys("MD61");
Thread.sleep(1200);
driver.findElement(By.id("TCode-launchBtn-content")).click();
Thread.sleep(1200);
driver.switchTo().defaultContent();
WebElement iframe = driver.findElement(By.id("ITSFRAME1"));
driver.switchTo().frame(iframe);
/*driver.switchTo().frame(driver.findElement(By.xpath("//span[#id='M0:46:::4:2-imgSymb']")));
driver.findElement(By.xpath("//span[#id='M0:46:::4:2-imgSymb']")).sendKeys("ABC");*/
//driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
//Thread.sleep(1600);
/*driver.switchTo().frame("ITSFRAME1");
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("ITSFRAME1"));*/
/*WebElement E1 = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("M0:46:::4:2-imgStd")));
WebElement E1 = driver.findElement(By.xpath("//span[#id='M0:46:::4:2-imgSymb']"));
E1.click();*/
//driver.findElement(By.id("M0:46:::4:2-imgStd")).click();
//driver.findElement(By.xpath("//span[#id='M0:46:::4:2-imgStd']")).click();
//Thread.sleep(1200);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
Your first xpath for the element and the id for the iframe are correct, but as the window is getting opened in a new tab, you need to switch the driver to the new tab.
So, instead of using driver.switchTo().defaultContent();
You need to use:
ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs.get(1));
And if you want to switch to the original tab, you need to use:
driver.switchTo().window(tabs.get(0));
How should I use sendKeys in loop? First time sendKeys work correct, but second time, on the new page - exception.
public class main {
public static void main(String args[]) throws Exception{
System.setProperty("webdriver.gecko.driver", "C:\\Users\\asdasd\\Desktop\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.kommersant.ru");
Scanner scanner = new Scanner(System.in);
while(true) {
WebElement search = driver.findElement(By.cssSelector(".search__input"));
// WebElement searchButton = driver.findElement(By.cssSelector(".search__button"));
String s = scanner.nextLine();
if(s.equals("exit")){
break;
}
else {
WebDriverWait wait = new WebDriverWait(driver, 10);
search.sendKeys(s);
WebElement searchButton = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".search__button")));
searchButton.click();
searchButton.click();
}
}
driver.quit();
}
}
Try to get your loop condition right.The problem lies there.
I am working on contacts creation page in www.salesforce.com developer login account. Anybody can create a free developer login account and access this page.
I am unable to switch between frames in Lookup window. There are two frames, one is search frame with textbox and button to search and below that is results frame for displaying search results with hyperlinks for selection. I am specifying the frames by frame name or id, but webDriver switches to search frame and does the searching but then is not able to locate the results frame with NoSuchFrameException.
If I do not switch to search frame initially but directly switch to results frame, it is indeed successful in the locating the results frame which displays results of some recent searches done by default.
How do I switch from search frame to results frame ? Given below is my code
public class Acc_Parent
{
WebDriver driver;
FileInputStream fis;
XSSFWorkbook wb;
XSSFSheet sh;
#Test
public void createParent() throws IOException, InterruptedException, FileNotFoundException
{
driver = new FirefoxDriver();
//System.setProperty("webdriver.chrome.driver", "D:/chromedriver_win32/chromedriver.exe");
//driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.get("https://test.salesforce.com");
fis = new FileInputStream("C:/Users/psit/Documents/Login.xlsx");
wb = new XSSFWorkbook(fis);
sh = wb.getSheetAt(0);
driver.findElement(By.xpath(".//*[#id='username']")).sendKeys(sh.getRow(1).getCell(0).getStringCellValue());
driver.findElement(By.xpath(".//*[#id='password']")).sendKeys(sh.getRow(1).getCell(1).getStringCellValue());
driver.findElement(By.xpath(".//*[#id='Login']")).click();
fis = new FileInputStream("C:/Users/psit/Documents/Input.xlsx");
wb = new XSSFWorkbook(fis);
sh = wb.getSheet("Parent");
driver.findElement(By.xpath(".//*[#id='Account_Tab']/a")).click();
driver.findElement(By.xpath(".//*[#id='hotlist']/table/tbody/tr/td[2]/input")).click();
driver.findElement(By.xpath(".//*[#id='j_id0:acctFrm:nmsrch']")).sendKeys(sh.getRow(1).getCell(1).getStringCellValue());
driver.findElement(By.xpath(".//*[#id='j_id0:acctFrm']/div[1]/div[2]/table/tbody/tr/td[2]/input")).click();
try
{
driver.findElement(By.linkText("click here")).click();
driver.findElement(By.xpath(".//*[#id='parentAcc']")).sendKeys(sh.getRow(1).getCell(1).getStringCellValue());
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[#id='childAcc']")).sendKeys(sh.getRow(1).getCell(2).getStringCellValue());
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[#id='pg:acc:pb:acctAdd:rptAddFields:0:actFields']")).sendKeys(sh.getRow(1).getCell(3).getStringCellValue());
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[#id='pg:acc:pb:acctAdd:rptAddFields:2:actFields']")).sendKeys(sh.getRow(1).getCell(4).getStringCellValue());
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[#id='pg:acc:pb:acctAdd:rptAddFields:4:actFields']")).sendKeys(sh.getRow(1).getCell(5).getStringCellValue());
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[#id='pg:acc:pb:acctAdd:rptAddFields:6:actFields']")).sendKeys(sh.getRow(1).getCell(6).getStringCellValue());
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[#id='pg:acc:pb:acctAdd:rptAddFields:8:actFields']")).sendKeys(Integer.toString((int)sh.getRow(1).getCell(7).getNumericCellValue()));
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[#id='pg:acc:pb:acctAdd:rptAddFields:1:actFields']")).sendKeys(sh.getRow(1).getCell(8).getStringCellValue());
Thread.sleep(2000);
driver.findElement(By.xpath(".//*[#id='pg:acc:pb:acctAdd:rptAddFields:3:actFields']")).sendKeys(sh.getRow(1).getCell(9).getStringCellValue());
String mainWindow = driver.getWindowHandle();
driver.findElement(By.xpath(".//*[#id='pg:acc:pb:acctAdd:rptAddFields:5:actFields_lkwgt']/img")).click();
Thread.sleep(5000);
Set<String> winhand = driver.getWindowHandles();
for(String str : winhand)
{
if(!str.equalsIgnoreCase(mainWindow))
{
driver.switchTo().window(str);
break;
}
}
try
{
driver.switchTo().frame("searchFrame");
driver.findElement(By.xpath(".//*[#id='lksrch']")).sendKeys(sh.getRow(1).getCell(10).getStringCellValue());
driver.findElement(By.xpath(".//*[#id='theForm']/div/div[2]/input[2]")).click();
Thread.sleep(5000);
driver.switchTo().frame("resultsFrame");
driver.findElement(By.linkText(sh.getRow(1).getCell(10).getStringCellValue())).click();
driver.switchTo().window(mainWindow);
driver.findElement(By.xpath(".//*[#id='pg:acc:pb:acctAdd:rptAddFields:7:actFields_lkwgt']/img")).click();
Thread.sleep(5000);
Set<String> winhandle = driver.getWindowHandles();
for(String str : winhandle)
{
if(!str.equalsIgnoreCase(mainWindow))
{
driver.switchTo().window(str);
break;
}
}
try
{
driver.switchTo().frame("searchFrame");
driver.findElement(By.xpath(".//*[#id='lksrch']")).sendKeys(sh.getRow(1).getCell(11).getStringCellValue());
driver.findElement(By.xpath(".//*[#id='theForm']/div/div[2]/input[2]")).click();
Thread.sleep(5000);
driver.switchTo().frame("resultsFrame");
driver.findElement(By.linkText(sh.getRow(1).getCell(11).getStringCellValue())).click();
driver.switchTo().window(mainWindow);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println();
driver.close();
driver.switchTo().window(mainWindow);
System.out.println("State/Region not Found");
}
}
catch(Exception e)
{
e.printStackTrace();
System.out.println();
driver.close();
driver.switchTo().window(mainWindow);
}
driver.findElement(By.xpath(".//*[#id='pg:acc:pb:j_id34:save']")).click();
Before switching to resultsFrame try to switch to defaultContent or your main frame and then switch to resultsFrame. The thing is webdriver searches the frame in current context. So under searchFrame it will never find the resultsFrame (As both might be under main frame).
Hope this helps.
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>