Appium Parallel OpenSTF

Appium Parallel Execution on OpenSTF

In the last post, we have seen how to execute appium tests in parallel using Selenium Grid. In this post, I’m going to show you how we can use OpenSTF, a Smartphone Test Farm – open source tool and execute our tests in parallel.

First clone this repo:

git clone https://github.com/email2vimalraj/appium-stf-example.git

Now let’s setup the required tools:
1. OpenSTF – Kindly follow the github instructions to install the openstf in your local machine
2. Appium – Download and install as per the documentation
3. Maven

Running test:
1. Make sure your stf is running.
2. Generate the Access Token from your stf settings page and copy it to your clipboard. (Settings > Keys > + > Give some title > Generate New Token).
3. Open src/test/java/com/vimalselvam/stf/AndroidTest and change the following:
1. STF_SERVICE_URL to your actual STF URL.
2. ACCESS_TOKEN to the copied access token from the step #2.
3. Update parallelDp data provider method to the list of device serial ids connected to your machine.
4. From terminal, cd to the cloned directory and run mvn clean test.

Demo

24 Replies to “Appium Parallel Execution on OpenSTF”

  1. Hi Vimal,

    I am using pom

    when I run the code applying your changes, it is not identifyig the serialid. But I took your code and run it, it is working.
    Default test name
    Default test name

    This is my base class
    package com.wadhwani.common;

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.net.MalformedURLException;
    import java.net.URISyntaxException;
    import java.net.URL;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.util.Date;
    import java.util.Properties;
    import java.util.Timer;
    import java.util.TimerTask;
    import java.util.concurrent.TimeUnit;

    import org.apache.commons.exec.CommandLine;
    import org.apache.commons.exec.DefaultExecuteResultHandler;
    import org.apache.commons.exec.DefaultExecutor;
    import org.apache.log4j.Logger;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.testng.annotations.*;

    import com.WadhwaniDesktop.com.InstituteCourseCreation;

    //import com.WadhwaniDesktop.com.InstituteCourseCreation;

    //import com.WadhwaniDesktop.com.InstituteCourseCreation;
    //import com.wadhwani.pages.Loginpage;

    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.android.*;
    import io.appium.java_client.remote.MobileCapabilityType;
    import io.appium.java_client.service.local.AppiumDriverLocalService;

    public class AppUtilWithDesktopScript {

    public static AndroidDriver driver;
    public  String deviceSerial;
    public AppiumDriverLocalService service;
    public DeviceApi deviceApi;
    private static Process process;
    
    public static Properties config = null;
    public static Logger log = Logger.getLogger("deployingLogger");
    
    public static final String STF_SERVICE_URL = "http://localhost:7100/#!/devices";  // Change this URL
    public static final String ACCESS_TOKEN = "eba0c71e5d6440d88fe034edf8363255d1c35fc75ea34ff898e31d0c58d8352a";  // Change this access token
    
    @DataProvider(name="devicenames")
    public Object[][] parallelDp() {
        return new Object[][] {
            {"5d6ef2bd"},    // Change the device serial
            {"ZY2232TB7B"},    // Change the device serial
    
        };              
    }
    
    @Factory(dataProvider="devicenames")
    public  AppUtilWithDesktopScript(String deviceSerial) {
        this.deviceSerial = deviceSerial;
        System.out.println(this.deviceSerial);
    
    }
    
    public void createAppiumService() {
        this.service = AppiumDriverLocalService.buildDefaultService();
        this.service.start();
    }
    
    public void connectToStfDevice() throws MalformedURLException, URISyntaxException {
        STFService stfService = new STFService(STF_SERVICE_URL,
                ACCESS_TOKEN);
        this.deviceApi = new DeviceApi(stfService);
        this.deviceApi.connectDevice(this.deviceSerial);
    
    }
    
    @BeforeSuite
    public void AppUtil()
    
    {
    
        try{
    
            config = new Properties();
            FileInputStream fs;
    
            fs = new FileInputStream(System.getProperty("user.dir")+"//src//test//java//com//wadhwani//common//Config.properties");
            config.load(fs);
    
        }
        catch(Exception e) {
            e.printStackTrace();
    
        }
    }
    
    /*@BeforeSuite
            public static void lodingTheFile() throws Exception {
    
                InstituteCourseCreation BaseClassobj=new InstituteCourseCreation();
                BaseClassobj.createTheCourse(); 
    
            }*/
    
    @BeforeMethod
    public  void setUpAndroid() throws MalformedURLException, URISyntaxException { 
        /*InstituteCourseCreation BaseClassobj=new InstituteCourseCreation();
                BaseClassobj.createTheCourse(); */
    
        /*if (config.getProperty("appTest").equals("Device"))
         * 
                {*/
    
        String workingDir = System.getProperty("user.dir");
    
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        // desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME,"Appium");
        desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "ANDROID");
        desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "ANDROID");
        desiredCapabilities.setCapability("udid", this.deviceSerial);
        desiredCapabilities.setCapability(MobileCapabilityType.APP,
                new File(workingDir+"//Resources//app//LearnWise-1.0").getAbsolutePath());
    
        connectToStfDevice();
        createAppiumService();
        driver = new AndroidDriver(this.service.getUrl(), desiredCapabilities);
        driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
    }
    /*log.debug("Loding the Android device capabalities");
                    String workingDir = System.getProperty("user.dir");
                    File app = new File(workingDir+config.getProperty("buildpathD"));
                    System.out.println(app);
                    DesiredCapabilities capabilities = new DesiredCapabilities();
                    capabilities.setCapability("automationName", config.getProperty("automationName"));
                    capabilities.setCapability("device",config.getProperty("device"));
                    capabilities.setCapability("deviceName", config.getProperty("deviceName"));
                    capabilities.setCapability("platformVersion", config.getProperty("platformVersion"));
                    capabilities.setCapability("platformName", config.getProperty("platformName"));
                    //capabilities.setCapability("resetKeyboard", true);
                    //capabilities.setCapability("unicodeKeyboard", true);
                    capabilities.setCapability("app", app.getAbsolutePath());
                    capabilities.setCapability("newCommandTimeout", "600000");
                    capabilities.setCapability("activityname",config.getProperty(""));
                    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
                            capabilities);
                    capabilities.setCapability("appWaitActivity", true);
                    driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
                    capabilities.setCapability("SESSION_OVERRIDE", true); */
    
    /*else if(config.getProperty("appTest").equals("Emulator"))
                {
                    String workingDir = System.getProperty("user.dir");
                    System.out.println(workingDir);
    
                    File app = new File(workingDir+config.getProperty("buildpathE"));
                    DesiredCapabilities capabilities = new DesiredCapabilities();
                    capabilities.setCapability("automationName", config.getProperty("automationNameE"));
                    capabilities.setCapability("device",config.getProperty("deviceE"));
                    capabilities.setCapability("deviceName",config.getProperty("deviceNameE"));
                    capabilities.setCapability("platformVersion", config.getProperty("platformVersionE"));
                    capabilities.setCapability("platformName", config.getProperty("platformNameE"));
                    capabilities.setCapability("newCommandTimeout", 360);
                    capabilities.setCapability("app", app.getAbsolutePath());
                    capabilities.setCapability("appWaitActivity", true);
                    //capabilities.setCapability("resetKeyboard", true);
                    //capabilities.setCapability("unicodeKeyboard", true);
                    //capabilities.setCapability("SESSION_OVERRIDE", true);
                    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
                            capabilities);
                    driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
    
                }
    
            }*/
    /*  @BeforeMethod(dependsOnMethods={"closeApp"})
    
            public void OpenApp() throws IOException, InterruptedException {
                driver.closeApp();
    
            } */
    
    @AfterMethod
    public void closeApp() throws IOException, InterruptedException {
        driver.closeApp();
        driver.launchApp();
    
    }
    
    @AfterMethod
    public void teardown() throws IOException, InterruptedException {
        //driver.removeApp("com.wadhwani.learnwise");
    
        driver.quit();
        if (this.service.isRunning()) {
            service.stop();
            this.deviceApi.releaseDevice(this.deviceSerial);
        }
    
    }
    

    }

    This the page class

    package com.wadhwani.students.tests;
    import org.testng.annotations.Test;
    import org.testng.AssertJUnit;
    import org.testng.annotations.Test;
    import org.testng.AssertJUnit;
    import org.testng.annotations.Test;
    import org.testng.AssertJUnit;
    import org.testng.annotations.Test;
    import org.testng.annotations.Test;
    import org.testng.annotations.Test;
    import org.testng.AssertJUnit;
    import org.testng.annotations.Test;
    import org.testng.annotations.Test;
    import org.testng.annotations.Test;
    import org.testng.AssertJUnit;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.sql.SQLException;
    import java.text.ParseException;
    import java.util.Date;
    import java.util.Properties;
    import java.util.Timer;
    import java.util.TimerTask;
    import java.util.concurrent.Executors;
    import java.util.concurrent.ScheduledExecutorService;
    import java.util.concurrent.TimeUnit;
    
    import org.openqa.selenium.WebElement;
    import org.testng.Assert;
    import org.testng.IRetryAnalyzer;
    import org.testng.ITestResult;
    import org.testng.Reporter;
    import org.testng.annotations.Test;
    import com.mysql.jdbc.log.Log;
    import com.wadhwani.common.*;
    import com.wadhwani.pages.EnterBatchDetailsPage;
    import com.wadhwani.pages.FirstTimeBatchPage;
    import com.wadhwani.pages.ForAlreadyCreatedBatchPage;
    import com.wadhwani.pages.Loginpage;
    import com.wadhwani.pages.ModifyCourseplanPage;
    import com.wadhwani.pages.SelectCoursePage;
    import com.wadhwani.pages.SplashScreenPage;
    import com.wadhwani.pages.YourProfilePage;
    import com.wadhwani.pages.facultyParticipatescreen;
    import com.wadhwani.students.pages.MainLoginPage;
    import com.wadhwani.students.pages.SideBarPage;
    import com.wadhwani.students.pages.StudentBatchPage;
    import com.wadhwani.students.pages.CourseDetailsPage;
    import com.wadhwani.students.pages.StudentCoursesPage;
    import com.wadhwani.students.pages.StudentLoginOptionsPage;
    import com.wadhwani.students.pages.StudentParticipants;
    import com.wadhwani.students.pages.StudentProfilePage;
    import com.wadhwani.students.pages.StudentRegistrationPage;
    import com.wadhwani.students.pages.StudentSelectInstitutePage;
    import com.wadhwani.students.pages.StudentSplashScreenPage;
    import com.WadhwaniDesktop.com.*;
    
    public class StudentBatchWithWebTest extends AppUtilWithDesktopScript {
    
        public StudentBatchWithWebTest(String deviceSerial) {
            super(deviceSerial);
            // TODO Auto-generated constructor stub
        }
        /*public StudentBatchWithWebTest(String deviceSerial) {
            super(deviceSerial);*/
            // TODO Auto-generated constructor stub
    
        StudentSplashScreenPage StudentSplashScreenPageObj;
        StudentLoginOptionsPage StudentLoginPageObj;
        StudentRegistrationPage StudentRegistrationPageObj;
        StudentProfilePage StudentProfilePageObj;
        StudentSelectInstitutePage StudentSelectInstitutePageObj;
        MainLoginPage MainLoginPageObj;
        StudentCoursesPage StudentCoursesPageObj;   
        CommonUtils CommonUtilsObj;
        SplashScreenPage SplashScreenPageObj;
        Loginpage LoginpageObj;
        InstituteCourseCreation InstituteCourseCreationObj;
        YourProfilePage YourProfilePageObj;
        FirstTimeBatchPage FirstTimeBatchPageObj;
        EnterBatchDetailsPage EnterBatchDetailsPageObj;
        CourseDetailsPage OrientationProgramInEnterpriseObj;
        CourseDetailsPage CourseDetailsPageObj;
        StudentBatchPage StudentBatchPageObj;
        facultyParticipatescreen facultyParticipatescreenOBJ;
    
        public static String SecoundStu;
    
        /*
         * 
         * 1. verify the screen ui with the design specifications
            2. Verify the batch duration and the no of students are displayed correctly
         */
    
        @Test(priority=1,alwaysRun=true,enabled=true)
        public void verifyThedurationAndDATE() throws InterruptedException, IOException, ParseException{
            SplashScreenPageObj = new SplashScreenPage(driver);
            SplashScreenPageObj.clikOnFaculty();
            LoginpageObj= new Loginpage(driver);    
            LoginpageObj.getUsernameFromWeb();/* Get the Username of Faculty from the web */
            LoginpageObj.getPasswordFromweb();/* Get the Password of Faculty from the web */
            CommonUtilsObj=new CommonUtils(driver);
            CommonUtilsObj.hiddingTheKeyBoard();
            LoginpageObj.clickOnLogin();
            Thread.sleep(3000);
            YourProfilePageObj=new YourProfilePage(driver);
            YourProfilePageObj.EnterMobileNumber("9878987789");
            YourProfilePageObj.EnterNewPassword("testing");
            CommonUtilsObj=new CommonUtils(driver);
            CommonUtilsObj.hiddingTheKeyBoard();
            YourProfilePageObj.clickSubmitButton();
            FirstTimeBatchPageObj=new FirstTimeBatchPage(driver);
            FirstTimeBatchPageObj.ClickOnAddBatch();
            SelectCoursePage SelectCoursePageObj=new SelectCoursePage(driver);
            SelectCoursePageObj.selectTheFirstCourse();
            SelectCoursePageObj.clickOnNextButton();
            EnterBatchDetailsPageObj=new EnterBatchDetailsPage(driver);
            EnterBatchDetailsPageObj.ClickONumberOFStudents();
            String noOfStu="4";
            EnterBatchDetailsPageObj.SendKeysNumberOFStudents(noOfStu);
            EnterBatchDetailsPageObj.ClickONSaveButtonOFnumberOFstuPOPUP();
            EnterBatchDetailsPageObj.isBatchNameEditable("Batch1");
            CommonUtilsObj=new CommonUtils(driver);
            CommonUtilsObj.hiddingTheKeyBoard();
            EnterBatchDetailsPageObj.ClickOnTheStartField();        
            EnterBatchDetailsPageObj.ClickOnOKButtonOnTheCalender();
            String Startdate=EnterBatchDetailsPageObj.getThetextStartDate();
            System.out.println(Startdate);
            String trimmonthStartDate=Startdate.substring(5, 9);
            System.out.println(trimmonthStartDate);
            String trimDayStartDate=Startdate.substring(10,11);
            System.out.println(trimDayStartDate);
            EnterBatchDetailsPageObj.ClickOnEndDay();   
            EnterBatchDetailsPageObj.ClickOnOKButtonOnTheCalender();
            String Enddate=EnterBatchDetailsPageObj.getTheTextOfEndDay();
            System.out.println(Enddate);
            String trimmonthEndDate=Enddate.substring(5, 8);
            System.out.println(trimmonthEndDate);
            String trimDateEndDate=Enddate.substring(9,11);
            System.out.println(trimDateEndDate);
            EnterBatchDetailsPageObj.clickONPrefferdDayfield();
            EnterBatchDetailsPageObj.selectDayFromPrefferdDays(2);
            EnterBatchDetailsPageObj.ClickOnSaveButtonofPrefferdDayspopup();
            EnterBatchDetailsPageObj.ClickonClassRoom();
            EnterBatchDetailsPageObj.popupOFClassRoom("Classroom1");
            EnterBatchDetailsPageObj.clickOnSavePopUPClassroom();
            EnterBatchDetailsPageObj.ClickonActivityRoom();
            EnterBatchDetailsPageObj.popupOfActivityRoom("Activity1");
            EnterBatchDetailsPageObj.clickOnSavePopUPActivityroom();
            EnterBatchDetailsPageObj.clickOnNextButton();
            Thread.sleep(2000);
            ModifyCourseplanPage ModifyCourseplanPageObj=new ModifyCourseplanPage(driver);
            ModifyCourseplanPageObj.FinshButton();
            Thread.sleep(1000);
            FirstTimeBatchPage FirstTimeBatchPageObj=new FirstTimeBatchPage(driver);
            FirstTimeBatchPageObj.ClickOnHamburgerIcon();
            FirstTimeBatchPageObj.Logout();
            Thread.sleep(2000);
            StudentSplashScreenPageObj=new StudentSplashScreenPage(driver);
            StudentSplashScreenPageObj.ClickONTheStudentLoginButton();
            StudentLoginPageObj=new StudentLoginOptionsPage(driver);
            StudentLoginPageObj.ContinueWithEmail();
            StudentRegistrationPageObj=new StudentRegistrationPage(driver);
            StudentRegistrationPageObj.enterUsername("student1");
            CommonUtilsObj=new CommonUtils(driver);
            StudentRegistrationPageObj.enterEmailID(CommonUtilsObj.generateEmail(8));
            StudentRegistrationPageObj.EnterPassword("testing123");
            CommonUtilsObj.hiddingTheKeyBoard();
            StudentRegistrationPageObj.clickOnRegistorBttn();
            StudentProfilePageObj=new StudentProfilePage(driver);
            StudentProfilePageObj.enterMobielNumber("9878987898");
            StudentProfilePageObj.clickONInstitute();
            StudentProfilePageObj.clickONInstitutesendWebIns();
            StudentSelectInstitutePageObj=new StudentSelectInstitutePage(driver);
            StudentSelectInstitutePageObj.selectFirstInstituteFromList();
            StudentProfilePageObj=new StudentProfilePage(driver);
            StudentProfilePageObj.ClickOnSubmit();
            Thread.sleep(5000); 
            StudentCoursesPageObj=new StudentCoursesPage(driver);
            StudentCoursesPageObj.SelectTheCourse();
            CourseDetailsPageObj=new CourseDetailsPage(driver);
            CourseDetailsPageObj.ClickOnjoinBatch();
            CourseDetailsPageObj.ClickOnPopUP();
            CourseDetailsPageObj.ClickOnYesButton();
            Thread.sleep(2000);
            StudentBatchPageObj=new StudentBatchPage(driver);
            AssertJUnit.assertTrue(StudentBatchPageObj.gettextWaitingForApp().contains("WAITING FOR APPROVAL"));
            System.out.println(StudentBatchPageObj.getTextOfBatchDate().contains(trimmonthStartDate));
            AssertJUnit.assertTrue(StudentBatchPageObj.getTextOfBatchDate().contains(trimmonthStartDate));
            AssertJUnit.assertTrue(StudentBatchPageObj.getTextOfBatchDate().contains(trimmonthEndDate));
            AssertJUnit.assertTrue(StudentBatchPageObj.getTextOfBatchDate().contains(trimDayStartDate));
            AssertJUnit.assertTrue(StudentBatchPageObj.getTextOfBatchDate().contains(trimDateEndDate));
            AssertJUnit.assertTrue(StudentBatchPageObj.getNoStude().contains(noOfStu));
            CommonUtilsObj=new CommonUtils(driver);
            CommonUtilsObj.takeScreenShot("verifyThedurationAndDATE");
    
        }
    
        /*
         * 1. Open a batch and select the participant icon
           2. verify all the students joined the batch is visible in the participant screen
           3. Verify the profile image and student name is clearly visible for all
         * 
         * 
         * 
         */
        //*******PENDING******************************************//
        @Test(priority=2,alwaysRun=true,enabled=true)
        public void verifyTheparticipant() throws InterruptedException, IOException, ParseException{
            StudentSplashScreenPageObj=new StudentSplashScreenPage(driver);
            StudentSplashScreenPageObj.ClickONTheStudentLoginButton();
            StudentLoginPageObj=new StudentLoginOptionsPage(driver);
            StudentLoginPageObj.ContinueWithEmail();
            StudentRegistrationPageObj=new StudentRegistrationPage(driver);
            StudentRegistrationPageObj.enterUsername("student2");
            CommonUtilsObj=new CommonUtils(driver);
            SecoundStu=StudentRegistrationPageObj.enterEmailID(CommonUtilsObj.generateEmail(8));
            System.out.println(SecoundStu);
            StudentRegistrationPageObj.EnterPassword("testing123");
            CommonUtilsObj.hiddingTheKeyBoard();
            StudentRegistrationPageObj.clickOnRegistorBttn();
            StudentProfilePageObj=new StudentProfilePage(driver);
            StudentProfilePageObj.enterMobielNumber("9878987898");
            StudentProfilePageObj.clickONInstitute();
            StudentProfilePageObj.clickONInstitutesendWebIns();
            Thread.sleep(2000);
            StudentSelectInstitutePageObj=new StudentSelectInstitutePage(driver);
            StudentSelectInstitutePageObj.selectFirstInstituteFromList();
            StudentProfilePageObj=new StudentProfilePage(driver);
            StudentProfilePageObj.ClickOnSubmit();
            Thread.sleep(5000); 
            StudentCoursesPageObj=new StudentCoursesPage(driver);
            StudentCoursesPageObj.SelectTheCourse();
            CourseDetailsPageObj=new CourseDetailsPage(driver);
            CourseDetailsPageObj.ClickOnjoinBatch();
            CourseDetailsPageObj.ClickOnPopUP();
            CourseDetailsPageObj.ClickOnYesButton();        
            StudentBatchPageObj=new StudentBatchPage(driver);
            StudentBatchPageObj.ClickOnHamburgerIcon();
            StudentBatchPageObj.ClickONLogout();
            SplashScreenPageObj = new SplashScreenPage(driver);
            SplashScreenPageObj.clikOnFaculty();
            LoginpageObj= new Loginpage(driver);    
            LoginpageObj.getUsernameFromWeb();
            LoginpageObj.Enterpassword("testing");
            CommonUtilsObj=new CommonUtils(driver);
            CommonUtilsObj.hiddingTheKeyBoard();
            LoginpageObj.clickOnLogin();
            Thread.sleep(3000);
            StudentBatchPage StudentBatchPageObj=new StudentBatchPage(driver);
            StudentBatchPageObj.clickOnBatchSection();      
            facultyParticipatescreenOBJ=new facultyParticipatescreen(driver);
            facultyParticipatescreenOBJ.ClickOnParticipanteIcon();
            StudentParticipants StudentParticipantsObj=new StudentParticipants(driver);
            StudentParticipantsObj.SelectTheAcceptButton();
            StudentParticipantsObj.clickOnBackButton();
            StudentBatchPageObj=new StudentBatchPage(driver);
            StudentBatchPageObj.clickOnBackButton();
            StudentBatchPageObj.ClickOnHamburgerIcon();
            StudentBatchPageObj.ClickONLogout();
            StudentSplashScreenPageObj=new StudentSplashScreenPage(driver);
            StudentSplashScreenPageObj.ClickONTheStudentLoginButton();
            StudentLoginPageObj=new StudentLoginOptionsPage(driver);
            StudentLoginPageObj.ContinueWithEmail();
            StudentRegistrationPageObj=new StudentRegistrationPage(driver);
            StudentRegistrationPageObj.clickOnLogin();
            MainLoginPageObj=new MainLoginPage(driver);
            MainLoginPageObj.enterEmailID(SecoundStu);
            MainLoginPageObj.enterPassword("testing123");
            CommonUtilsObj=new CommonUtils(driver);
            CommonUtilsObj.hiddingTheKeyBoard();
            LoginpageObj.clickOnLogin();
            Thread.sleep(3000);
            StudentBatchPageObj=new StudentBatchPage(driver);
            AssertJUnit.assertEquals(StudentBatchPageObj.StatusAfterAccepting(), "UPCOMING");
            StudentBatchPageObj.clickOnBatchSection();
            AssertJUnit.assertTrue(StudentBatchPageObj.verifyTheCurrentDateWithUpcomignItemDate());
            Assert.assertNotNull(StudentBatchPageObj.checkBatchDetails());
            StudentBatchPageObj.ClickOnParticipanteIcon();
            AssertJUnit.assertEquals(StudentParticipantsObj.getTestOFStudent(0).trim(), "student1");
            CommonUtilsObj=new CommonUtils(driver);
            CommonUtilsObj.takeScreenShot("verifyTheparticipant");
    
        }
        /*
         * 
         * verify when student open a batch, in assignment section the submitted time is displayed correctly if the assignment is submitted
         */
    
        @Test(priority=3,alwaysRun=true,enabled=true)
        public void verifyAssignment() throws InterruptedException, IOException, ParseException{
            StudentSplashScreenPageObj=new StudentSplashScreenPage(driver);
            StudentSplashScreenPageObj.ClickONTheStudentLoginButton();
            StudentLoginPageObj=new StudentLoginOptionsPage(driver);
            StudentLoginPageObj.ContinueWithEmail();
            StudentRegistrationPageObj=new StudentRegistrationPage(driver);
            StudentRegistrationPageObj.clickOnLogin();
            MainLoginPageObj=new MainLoginPage(driver);
            System.out.println(SecoundStu);
            MainLoginPageObj.enterEmailID(SecoundStu);
            MainLoginPageObj.enterPassword("testing123");
            CommonUtilsObj=new CommonUtils(driver);
            CommonUtilsObj.hiddingTheKeyBoard();
            MainLoginPageObj.clickOnTheLoginButtn();
            Thread.sleep(3000);
            StudentBatchPageObj=new StudentBatchPage(driver);
            StudentBatchPageObj.clickOnBatchSection();
            CourseDetailsPageObj=new CourseDetailsPage(driver);
            CourseDetailsPageObj.ClickOnAssignmentButton();
            CourseDetailsPageObj.clickONYesButton();
            Thread.sleep(1000);
            AssertJUnit.assertEquals(CourseDetailsPageObj.verifyStatusMessage(), "Submitted Just now");
            //      Appium is not supporting this functionality
            try {
                Thread.sleep(300000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            CourseDetailsPageObj=new CourseDetailsPage(driver);
            CourseDetailsPageObj.clickOnBackButton();
            StudentBatchPageObj=new StudentBatchPage(driver);
            StudentBatchPageObj.clickOnBatchSection();      
            //Assert.assertEquals(CourseDetailsPageObj.verifyStatusMessage(), "Submitted 5 min ago");   
            CommonUtilsObj=new CommonUtils(driver);
            CommonUtilsObj.takeScreenShot("verifyAssignment");
    
        }
        /*1. Login as student
        2. Open a batch from the list
        3.  Select the tick mark near an assignment
        4. User should get a dialogue box asking confirmation to submit the assignment
        5. Select ok and verify the assignment is marked as completed
        6. Verify the submitted ago time is displayed below the assignment
        7. Select the assignment and go to the submission tab and verify the submission status is updated there
        8. Login from a faculty and verify the submission status for the student is updated and time is displayed correctly
        9. verify for faculty, the assignment show the submission count correctly" */
    
        @Test(priority=4,alwaysRun=true,enabled=true)
        public void verifyThesubmissioncount() throws InterruptedException, IOException{
    
            StudentSplashScreenPageObj=new StudentSplashScreenPage(driver);
            StudentSplashScreenPageObj.ClickONTheStudentLoginButton();
            StudentLoginPageObj=new StudentLoginOptionsPage(driver);
            StudentLoginPageObj.ContinueWithEmail();
            StudentRegistrationPageObj=new StudentRegistrationPage(driver);
            StudentRegistrationPageObj.clickOnLogin();
            MainLoginPageObj=new MainLoginPage(driver);
            System.out.println(SecoundStu);
            MainLoginPageObj.enterEmailID(SecoundStu);
            MainLoginPageObj.enterPassword("testing123");
            CommonUtilsObj=new CommonUtils(driver);
            CommonUtilsObj.hiddingTheKeyBoard();
            MainLoginPageObj.clickOnTheLoginButtn();
            Thread.sleep(3000);
            StudentBatchPageObj=new StudentBatchPage(driver);
            StudentBatchPageObj.clickOnBatchSection();      
            CourseDetailsPageObj=new CourseDetailsPage(driver);
            CourseDetailsPageObj.SelectTheSegmentWITHTickmarkticked();
            CourseDetailsPageObj.clickOnSubmittiontab();
            AssertJUnit.assertTrue(CourseDetailsPageObj.checkThesubmittedStatus());
            CourseDetailsPageObj.checkTheSubmittedTimeAmount();
            CourseDetailsPageObj.clickOnBackButton();
            CourseDetailsPageObj.clickOnBackButton();       
            FirstTimeBatchPage FirstTimeBatchPageObj=new FirstTimeBatchPage(driver);
            FirstTimeBatchPageObj.ClickOnHamburgerIcon();
            FirstTimeBatchPageObj.Logout();
            Thread.sleep(2000);
            SplashScreenPageObj = new SplashScreenPage(driver);
            SplashScreenPageObj.clikOnFaculty();
            LoginpageObj= new Loginpage(driver);    
            LoginpageObj.getUsernameFromWeb();
            LoginpageObj.Enterpassword("testing");
            CommonUtilsObj=new CommonUtils(driver);
            CommonUtilsObj.hiddingTheKeyBoard();
            LoginpageObj.clickOnLogin();
            Thread.sleep(3000);
            StudentBatchPageObj=new StudentBatchPage(driver);
            StudentBatchPageObj.clickOnBatchSection();
            CourseDetailsPageObj=new CourseDetailsPage(driver); 
            AssertJUnit.assertEquals(1,CourseDetailsPageObj.ScrollTillTheSubmittedStatusisFoundGetNumberOFstudentsSubmitted());
            CourseDetailsPageObj.SelectTheSegmentWITHTickmarkticked();
            CourseDetailsPageObj.clickOnSubmittiontab();
            //Assert.assertTrue(CourseDetailsPageObj.checkTheSubmittedTimeAmount());
            CommonUtilsObj=new CommonUtils(driver);
            CommonUtilsObj.takeScreenShot("verifyThesubmissioncount");
    
        }
    }
    

  2. Hi vimal,

    When I cloned the repository and made the changes as you have given above in the script, after running it I am getting a error as mentioned below:

    com.vimalselvam.DeviceApi isDeviceFound
    SEVERE: Device not found

    I tried debugging the error but not able to , Could you please help me here Vimal ?

    Thanks & Regards,
    Madan

    1. Sure I can help you. The basic debugging would be to check whether adb devices list your device or not. Because the isDeviceFound uses the adb command to get the device.

      1. Hi Vimal,

        Thank you for the clarification, I have got a new issue if you could help me with this it would be of great help for me.

        Its a very good article, helped me to automate scripts in devices using the sample code provided, but I am stuck in a point, like when I run the scripts in multiple devices instead of executing in parallel at a time, scripts are running sequentially that is one by one, but in the as per the information given in video scripts are running in parallel, So can you please guide me on how to run the scripts in parallel.

        Thanks in advance!!!

  3. Hi Vimal,

    Its a very good article, helped me to automate scripts in devices using the sample code provided, but I am stuck in a point, like when I run the scripts in multiple devices instead of executing in parallel at a time, scripts are running sequentially that is one by one, but in the as per the information given in video scripts are running in parallel, So can you please guide me on how to run the scripts in parallel.

    Thanks in advance!!!

  4. Hi Vimal,

    Thanks for the wonderful article and my question is like
    Using your code and changing according to our requirement, we are to able to run the scripts in two devices sequentially but not in parallel, but we want to run the scripts in such a way that execution takes simultaneously in both the devices at a time, can you please guide me on the same?
    Thanks in advance..!!

  5. Hi Vimal,

    Thanks for the good article and demo sample.
    I am trying to use the sample to confirm the parallel execution using stf but facing some issue.
    Environment is MAC (10.12.4)
    Appium v1.6.4
    chromedriver 2.28

    AndroidDriver (v1.17.1)

    T E S T S

    Running com.vimalselvam.stf.AndroidTest
    Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@2401f4c3
    [Appium] Welcome to Appium v1.6.4
    [Appium] Appium REST http interface listener started on 0.0.0.0:4723
    [HTTP] –> GET /wd/hub/status {}
    [debug] [MJSONWP] Calling AppiumDriver.getStatus() with args: []
    [debug] [MJSONWP] Responding to client with driver.getStatus() result: {“build”:{“version”:”1.6.4″,”revision”:null}}
    [HTTP] POST /wd/hub/session {“desiredCapabilities”:{“app”:”/Users/SCE-SP2/source/appium-stf-example/src/test/resources/ApiDemos-debug.apk”,”platformName”:”Android”,”udid”:”037c7e8b21525a55″,”deviceName”:”ANDROID”}}
    [debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{“app”:”/Users/source/appium-stf-example/src/test/resources/ApiDemos-debug.apk”,”platformName”:”Android”,”udid”:”037c7e8b21525a55″,”deviceName”:”ANDROID”},null,null,null,null]
    [debug] [BaseDriver] Event ‘newSessionRequested’ logged at 1493693124703 (11:45:24 GMT+0900 (JST))
    [Appium] Creating new AndroidDriver (v1.17.1) session
    [Appium] Capabilities:
    [Appium] app: ‘/Users/source/appium-stf-example/src/test/resources/ApiDemos-debug.apk’
    [Appium] platformName: ‘Android’
    [Appium] udid: ‘037c7e8b21525a55’
    [Appium] deviceName: ‘ANDROID’
    [debug] [AndroidDriver] AndroidDriver version: 1.17.1
    [BaseDriver] Session created with session id: 0a29d572-0d4a-4367-9580-61c6e51a0b49
    [debug] [AndroidDriver] Getting Java version
    [AndroidDriver] Java version is: 1.8.0_121
    [ADB] Checking whether adb is present
    [ADB] Using adb from /Users/SCE-SP2/Library/Android/sdk/platform-tools/adb
    [AndroidDriver] Retrieving device list
    [debug] [ADB] Trying to find a connected android device
    [debug] [ADB] Getting connected devices…
    [debug] [ADB] 2 device(s) connected
    [AndroidDriver] Error: Device 037c7e8b21525a55 was not in the list of connected devices

    1. adb devices -l
      List of devices attached
      43.21.214.95:7469 device product:nakasi model:Nexus_7 device:grouper
      43.21.214.95:7525 device product:hammerhead model:Nexus_5 device:hammerhead

          1. I’m not sure which one you are referring as device serial. As per your adb devices list, the device serial 43.21.214.95:7525 is mapped to Nexus_7.

  6. Following is what I tried
    Step 1 connect the devices using adb connect IP:port
    Step 2 execute mvn clean test

    I get the error as in previous attached log

    Another apporach
    Dont connect the devices usinh adb connect
    Then adb devices -l is empty
    In the case I get no device found error

    Please let me know what I am doing wrong

    1. I believe you’re trying to connect devices wirelessly. In this case your device serial will look like a host name with port.

  7. I have a stf setup on linux machine and all phone connected via usb hub.
    From development pc I am trying to connect using adb connect stf pc ip:port

  8. Dear Vimal, Thank you for your effort for the appium tests in parallel using OpenSTF. I am using Cucumber to run the program, so @Factory and @DataProvider is not working here. I can initialize just one final device serial number and it works for one device. May you please tell me how to pass multiple device serial number here in Cucumber option(e.g if there is no @Test case and just @Before and @After for cucumber option in AndroidTest class and the test will run from the feature file) or if you have any idea? I am waiting for your kind response. I am really sorry to take your time. Thank you very much.

Leave a Reply