Skip to content

Instantly share code, notes, and snippets.

@riteshkawadkar
Created December 7, 2021 09:41
Show Gist options
  • Save riteshkawadkar/9a1abd0dd46bf898e73e1a20105522c0 to your computer and use it in GitHub Desktop.
Save riteshkawadkar/9a1abd0dd46bf898e73e1a20105522c0 to your computer and use it in GitHub Desktop.
package bots;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.MobileCapabilityType;
public class LoginTest {
private final static String APPIUM_SERVER_URL = "http://127.0.0.1:4723/wd/hub";
// private final static String APPIUM_SERVER_URL = "http://0.0.0.0:4723/wd/hub";
private AppiumDriver<MobileElement> driver;
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
@BeforeTest(alwaysRun = true)
public void setup() throws Exception {
URL url = new URL(APPIUM_SERVER_URL);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.NO_RESET, true);
capabilities.setCapability(MobileCapabilityType.FULL_RESET, false);
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
// capabilities.setCapability(MobileCapabilityType.UDID, "emulator-5554");
capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "120");
capabilities.setCapability("autoGrantPermissions",true);
capabilities.setCapability("appPackage", "sg.bigo.live");
capabilities.setCapability("appActivity", "sg.bigo.live.home.MainActivity");
driver = new AppiumDriver<MobileElement>(url, capabilities);
}
@Test
public void openApp() throws MalformedURLException, InterruptedException
{
Date date = new Date();
System.out.println(formatter.format(date));
WebDriverWait wait = new WebDriverWait(driver, 240);
MobileElement signInWithPhone = (MobileElement) wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.FrameLayout[1]/android.widget.TextView"))));
signInWithPhone.click();
Thread.sleep(2000);
try {
MobileElement login = (MobileElement) wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("sg.bigo.live:id/action_login"))));
login.click();
Thread.sleep(2000);
}
catch (Exception e) {
// TODO: handle exception
}
Thread.sleep(4000);
MobileElement countryCode = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("sg.bigo.live:id/tv_country_code"))));
countryCode.click();
Thread.sleep(3000);
MobileElement countrySearch = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("sg.bigo.live:id/contact_search_et"))));
countrySearch.sendKeys("Russia");
Thread.sleep(1000);
MobileElement country = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.ListView/android.widget.RelativeLayout"))));
country.click();
Thread.sleep(4000);
MobileElement phoneNo = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("sg.bigo.live:id/et_phone_num"))));
phoneNo.sendKeys("9661362557");
try {
Thread.sleep(4000);
MobileElement next = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("sg.bigo.live:id/tv_next"))));
next.click();
}
catch (Exception e) {
// TODO: handle exception
}
Thread.sleep(4000);
MobileElement password = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("sg.bigo.live:id/et_password"))));
password.sendKeys("ss123456");
Thread.sleep(4000);
MobileElement next = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("sg.bigo.live:id/tv_next"))));
next.click();
Thread.sleep(4000);
MobileElement searchStream = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("sg.bigo.live:id/iv_search"))));
searchStream.click();
// Thread.sleep(4000);
// MobileElement searchInput= (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("sg.bigo.live:id/searchInput"))));
// searchInput.sendKeys("408694333");
//
//
// Thread.sleep(4000);
// MobileElement search = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("sg.bigo.live:id/iv_search"))));
// search.click();
//
Thread.sleep(4000);
MobileElement searchInput= (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("sg.bigo.live:id/searchInput"))));
searchInput.sendKeys("M3ntally-iLL");
Thread.sleep(4000);
MobileElement content = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("sg.bigo.live:id/searchRelatedContent"))));
content.click();
Thread.sleep(4000);
MobileElement host_tab = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//androidx.appcompat.app.ActionBar.y[@content-desc=\"Host\"]/android.view.ViewGroup/android.widget.TextView"))));
host_tab.click();
Thread.sleep(4000);
MobileElement follow = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("sg.bigo.live:id/iv_follow"))));
follow.click();
Thread.sleep(4000);
MobileElement live_tab = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//androidx.appcompat.app.ActionBar.y[@content-desc=\"LIVE\"]/android.view.ViewGroup/android.widget.TextView"))));
live_tab.click();
Thread.sleep(4000);
MobileElement live_content = (MobileElement) wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("sg.bigo.live:id/searchHomeLikeShadow"))));
live_content.click();
Thread.sleep(20000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment