Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bai2 #62

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Bai2 #62

wants to merge 5 commits into from

Conversation

tedufu
Copy link

@tedufu tedufu commented Aug 11, 2024

No description provided.

@duykhanhrc
Copy link
Member

package com;

import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;

import com.utils.BasicTest;
import com.utils.Utils;

import io.appium.java_client.android.Activity;
import io.appium.java_client.android.AndroidDriver;

public class LoginTest extends BasicTest {
    

    private final String SAUCELABAPP_ACTIVITY = "com.swaglabsmobileapp.MainActivity";
    private final String SAUCELABAPP_PACKAGE = "com.swaglabsmobileapp";

    @Test()
    public void loginTestSucess() throws Exception {
        // Launch app
        driver.startActivity(new Activity(SAUCELABAPP_PACKAGE, SAUCELABAPP_ACTIVITY));
        //Assert.assertEquals(driver.getCurrentUrl(), url);
        Utils.hardWait(8000); // wait 5s

        // locator ->  sendkey -> click login
        driver.findElement(By.xpath("//android.widget.EditText[@content-desc='test-Username']")).sendKeys("standard_user");

        // enter password
        driver.findElement(By.xpath("//android.widget.EditText[@content-desc=\"test-Password\"]")).sendKeys("secret_sauce");
        // click login
        driver.findElement(By.xpath("//android.view.ViewGroup[@content-desc=\"test-LOGIN\"]")).click();
        Utils.hardWait(9000);

        String errorMessage;
        // verify login
        try {
            errorMessage = driver.findElement(By.xpath("//android.view.ViewGroup[@content-desc=\"test-Error message\"]//android.widget.TextView")).getText();
        
            System.out.println(errorMessage);
        } catch (Exception e) {
            errorMessage = "";
        }
        

        Assert.assertEquals(errorMessage, "");
        // Assert.assertTrue(errorMessage.contains("Username is"));



        Utils.hardWait(); // 3s  




    }


    @Test()
    public void loginTestFailedUser() throws Exception {
        // Launch app
        driver.startActivity(new Activity(SAUCELABAPP_PACKAGE, SAUCELABAPP_ACTIVITY));
        //Assert.assertEquals(driver.getCurrentUrl(), url);
        Utils.hardWait(8000); // wait 5s

        // locator ->  sendkey -> click login
        driver.findElement(By.xpath("//android.widget.EditText[@content-desc='test-Username']")).sendKeys("");

        // enter password
        driver.findElement(By.xpath("//android.widget.EditText[@content-desc=\"test-Password\"]")).sendKeys("secret_sauce");
        // click login
        driver.findElement(By.xpath("//android.view.ViewGroup[@content-desc=\"test-LOGIN\"]")).click();
        Utils.hardWait(9000);


        // verify login
        String errorMessage;
        // verify login
        try {
            errorMessage = driver.findElement(By.xpath("//android.view.ViewGroup[@content-desc=\"test-Error message\"]//android.widget.TextView")).getText();
        
            System.out.println(errorMessage);
        } catch (Exception e) {
            errorMessage = "";
        }
        

        Assert.assertEquals(errorMessage, "Username is required");

        // Assert.assertEquals(errorMessage, "Username is required");
        // Assert.assertTrue(errorMessage.contains("Username is"));

        Utils.hardWait(); // 3s  




    }

}

String url = "https://automationtestpro.com/";
driver.get(url);
Assert.assertEquals(driver.getCurrentUrl(), url);
//@Test()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

un comment

errorMessage = "";
}
Assert.assertEquals(errorMessage, "Password is required");
//Assert.assertTrue(errorMessage.contains("Username is"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xoa

// click login
// driver.findElement(By.xpath("//android.view.ViewGroup[@content-desc=\"test-LOGIN\"]")).click();
loginPage.clickloginBtn();
Utils.hardWait(9000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chuyen qua xai explicitly wait

private final String SAUCELABAPP_PACKAGE = "com.swaglabsmobileapp";

@Test()
public void loginTest() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bookingTest

//Continue
//driver.findElement(By.xpath("//android.view.ViewGroup[@content-desc=\"test-CONTINUE\"]")).click();
informationPage.clickContinueBtn();
Utils.hardWait(9000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm hardwait


import io.appium.java_client.android.AndroidDriver;

public class BasePage {
Copy link
Member

@duykhanhrc duykhanhrc Sep 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protected WebElement findElementByLocator(By locator) {
        wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
        return this.driver.findElement(locator);
    }

protected void waitForElementVisible(By locator) {
        wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
    }
//
    protected void waitForElementClickable(By locator) {
        wait.until(ExpectedConditions.elementToBeClickable(locator));
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants