Commit 96c4627a authored by Sergey Nazarenko's avatar Sergey Nazarenko
Browse files

Created bash script to get UDID from connected device.

parent 2d7bdae4
This diff is collapsed.
package Pages;
import io.appium.java_client.android.AndroidDriver;
public class CreateAccount
{
AndroidDriver driver;
Datas datas = new Datas();
Selectors selectors = new Selectors();
public void create_account_invalid_datas()
{
driver.findElement(selectors.createAccount).click();
driver.findElement(selectors.nextStepButton).click();
}
}
package Pages;
import java.util.Arrays;
import java.util.List;
public class Datas
{
//Login
String validPhone = "+380502972012";
String validSmsCode = "111111";
List<String> invalidLoginPhone = Arrays.asList(" +380502972012",
"#380502972012", "@380502972012",
"38050297201", " +380502972012", "3805029+72012", "12381298318923");
List<String> invalidSmsCode = Arrays.asList( " ", "543632","1111", "2222222", " 111111",
"1234567890123456789012345678901234567890");
//Create Account
}
package Pages;
import Utils.AndroidSetup;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.NoSuchElementException;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import Pages.Selectors;
import Pages.Datas;
public class LoginPage {
public class LoginPage
{
AndroidDriver driver;
By signIn = By.id("btn_sign_in");
By signIn2 = By.id("btn_sing_in");
By createAccount = By.id("btn_create_account");
By phoneInput = By.id("et_phone");
By sendCode = By.id("btn_send_code");
By keyInput = By.id("et_security_key");
Datas datas = new Datas();
Selectors selectors = new Selectors();
public LoginPage(AndroidDriver driver) {
this.driver = driver;
}
String validPhone = "+380502972012";
String validSmsCode = "111111";
List<String> invalidLoginPhone = Arrays.asList(" +380502972012","#380502972012", "@380502972012",
"38050297201", " +380502972012", "3805029+72012", "12381298318923");
List<String> invalidSmsCode = Arrays.asList( " ", "543632","1111", "2222222", " 111111",
"1234567890123456789012345678901234567890");
public void invalidLogin() throws InterruptedException {
driver.findElement(signIn).click();
for (String invalidPhone : invalidLoginPhone) {
driver.findElement(phoneInput).clear();
driver.findElement(phoneInput).sendKeys(invalidPhone);
// try {
// driver.findElement(By.xpath("//*[contains(text(),'The phone number entered is not valid')]"));
// }catch (NoSuchElementException ex){
// System.out.println(ex);
// }
public void invalid_data_login() throws InterruptedException
{
driver.findElement(selectors.signIn).click();
for (String invalidPhone : datas.invalidLoginPhone) {
driver.findElement(selectors.phoneInput).clear();
driver.findElement(selectors.phoneInput).sendKeys(invalidPhone);
driver.hideKeyboard();
driver.findElement(sendCode).click();
driver.findElement(phoneInput).clear();
driver.findElement(selectors.sendCode).click();
//driver.findElement(selectors.phoneInput).clear();
}
Assert.assertEquals( selectors.sign_in_text_view, "Sing in");
}
public void sign_in_button()
{
driver.findElement(selectors.signIn).click();
}
public void validLogin() {
driver.findElement(phoneInput).sendKeys(validPhone);
public void valid_phone_login() throws InterruptedException {
driver.findElement(selectors.phoneInput).sendKeys(datas.validPhone);
driver.hideKeyboard();
driver.findElement(sendCode).click();
driver.findElement(keyInput).clear();
driver.findElement(selectors.sendCode).click();
driver.wait(5000);
}
public void invalidCode()
public void invalid_code_login()
{
driver.findElement(keyInput).clear();
for (String invalidsmscode : invalidSmsCode)
driver.findElement(selectors.keyInput).clear();
for (String invalidsmscode : datas.invalidSmsCode)
{
driver.findElement(keyInput).sendKeys(invalidsmscode);
driver.findElement(selectors.keyInput).sendKeys(invalidsmscode);
driver.hideKeyboard();
driver.findElement(signIn2).click();
driver.findElement(keyInput).clear();
driver.findElement(selectors.signIn2).click();
driver.findElement(selectors.keyInput).clear();
}
}
public void validCode()
public void valid_code_login()
{
driver.findElement(keyInput).sendKeys(validSmsCode);
driver.findElement(signIn2).click();
driver.findElement(selectors.keyInput).sendKeys(datas.validSmsCode);
driver.findElement(selectors.signIn2).click();
}
}
......@@ -4,10 +4,27 @@ import org.openqa.selenium.By;
public class Selectors
{
//Login
By signIn = By.id("btn_sign_in");
By signIn2 = By.id("btn_sing_in");
By createAccount = By.id("btn_create_account");
By phoneInput = By.id("et_phone");
By sendCode = By.id("btn_send_code");
By keyInput = By.id("et_security_key");
By sign_in_text_view = By.id("tv_sign_in");
//Create account
By firstName = By.id("et_first_name");
By lastName = By.id("et_last_name");
By femaleRadioButton = By.id("rb_female");
By maleRadioButton = By.id("tv_male");
By birhDate = By.id("et_birthday");
By country = By.id("et_choose_contry");
By phoneNumber = By.id("et_phone_number");
By email = By.id("et_email");
By termsAndCoToggle = By.id("terms_and_conditions_switcher");
By nextStepButton = By.id("btn_next_step");
}
......@@ -11,9 +11,6 @@ import java.net.URL;
public class AndroidSetup
{
public AndroidDriver driver;
public AndroidSetup(AndroidDriver driver) {
this.driver = driver;
}
public static String White = "2101322bd623a34a";
public static String Black = "42031589dcde8100";
public String UDID = White;
......@@ -22,25 +19,9 @@ public class AndroidSetup
private String DeviceName = "device";
private String AutomationName = "Appium";
String device;
public String getUDID(String device) throws InterruptedException, MalformedURLException {
if (UDID == White)
{
device = White;
capabilities(White);
}
else
{
capabilities(Black);
}
return device;
}
public void capabilities(String device) throws InterruptedException, MalformedURLException {
public void capabilities(String udid) throws InterruptedException, MalformedURLException {
this.UDID = device;
this.UDID = udid;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("automationName", AutomationName);
......
......@@ -2,43 +2,62 @@ package Scenario;
import Utils.AndroidSetup;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.*;
import Pages.LoginPage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
import static Utils.AndroidSetup.Black;
import static Utils.AndroidSetup.White;
import static java.lang.System.console;
import static org.testng.Assert.assertNotNull;
import Utils.AndroidSetup;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class AppiumTest
{
AndroidDriver driver;
AndroidSetup androidSetup = new AndroidSetup(driver);
public AppiumTest() {
this.driver = driver;
}
@BeforeTest
public void setUp() throws MalformedURLException, InterruptedException {
//Here you change device UDID (ex. Black or White samsung)
//If you want to add new UDID, set it up in Utils/AndroidSetup.java
androidSetup.getUDID(White);
// DesiredCapabilities capabilities = new DesiredCapabilities();
// capabilities.setCapability("automationName", "Appium");
// capabilities.setCapability("platformName", "Android");
// capabilities.setCapability("udid", "42031589dcde8100");
// capabilities.setCapability("deviceName", "device");
// capabilities.setCapability("app", "/home/master/Desktop/Snaapy_07.07.17_11.15.apk");
// driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
public void setUp() throws IOException, InterruptedException
{
String[] cmd = new String[]{"/bin/bash", "./udid.sh"};
Process pr = Runtime.getRuntime().exec(cmd);
pr.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(
pr.getInputStream()));
String UDID;
while ((UDID = reader.readLine()) != null) {
System.out.println("Script output: " + UDID);
}
reader.close();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("automationName", "Appium");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("udid", UDID);
capabilities.setCapability("deviceName", "device");
capabilities.setCapability("app", "/home/master/Desktop/Snaapy_07.07.17_11.15.apk");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
......@@ -48,25 +67,20 @@ public class AppiumTest
driver.quit();
}
// @Test(priority = 1)
// public void not_correct_login_and_code() throws Exception
// {
// new LoginPage(driver).invalid_data_login();
// new LoginPage(driver).valid_phone_login();
//// new LoginPage(driver).invalid_code_login();
//// new LoginPage(driver).valid_code_login();
// }
@Test(priority = 1)
public void invalidLogin() throws Exception {
new LoginPage(driver).invalidLogin();
}
@Test(priority = 2)
public void validLogin() throws Exception {
new LoginPage(driver).validLogin();
}
@Test(priority = 3)
public void invalidCode() throws Exception {
new LoginPage(driver).invalidCode();
}
@Test(priority = 4)
public void validCode() throws Exception {
new LoginPage(driver).validCode();
public void correct_login_and_code() throws Exception
{
new LoginPage(driver).sign_in_button();
new LoginPage(driver).valid_phone_login();
new LoginPage(driver).valid_code_login();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment