Example usage for org.openqa.selenium WebElement getAttribute

List of usage examples for org.openqa.selenium WebElement getAttribute

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement getAttribute.

Prototype

String getAttribute(String name);

Source Link

Document

Get the value of the given attribute of the element.

Usage

From source file:com.mycompany.myselion.sample.selion.AppiumAndroidSeLionHubTest.java

License:Apache License

/**
 * This test demonstrates how to use SeLion for running tests against a Native ANDROID app using appium 
 * and apps placed in selion hub storage. 
 * <ul>/* w w w. j  a v a2s. com*/
 * <li>
 * An instance of selion grid should be spawned and the appium instance should be registered to this grid.</li>
 * <li>
 * The app selendroid-test-app-0.14.0.apk to be tested should be uploaded to SeLion hub storage 
 * provided by SeLion grid.</li>
 * <li>
 * The format of the appPath for the apps in the SeLion hub storage is as follows 
 * selion-hub-storage:{user-guid}:{folderName}:{file} where user-guid is a random unique guid and it is mandatory 
 * while uploading a file. foldername is an optional parameter and this test case is configured without folder name.</li>
 * </ul>
 */
@Test
@MobileTest(appPath = "selion-hub-storage:guid:selendroid-test-app-0.15.0.apk", device = "android:5.0.1", deviceType = "Android Emulator")
public void testWithNativeAppWithSelionHub() {
    RemoteWebDriver driver = Grid.driver();
    WebDriverWaitUtils.waitUntilElementIsVisible("io.selendroid.testapp:id/my_text_field");
    WebElement textField = driver.findElement(By.id("io.selendroid.testapp:id/my_text_field"));
    assertEquals("true", textField.getAttribute("enabled"));
    textField.sendKeys("Appium Android Native Test");
    assertEquals("Appium Android Native Test", textField.getText());
}

From source file:com.mycompany.myselion.sample.selion.AppiumIOSDemoTest.java

License:Apache License

/**
 * This test demonstrates how to use SeLion for running tests against a Native IOS app using appium.
 * <ul>//from  ww  w.ja  v  a 2  s.c o  m
 * <li>
 * An appium instance/server should be locally installed and running and point SeLion to this server using any of the following options. 
 * <ol>
 * <li>Through the JVM arguments -DSELION_SELENIUM_HOST and -DSELION_SELENIUM_PORT </li> (or)
 * <li>Through suite file &lt;parameter name="seleniumhost" value=""/&gt; and &lt;parameter name="seleniumport" value=""/&gt;</li>
 * </ol></li>
 * For setting up Appium iOS refer http://appium.io/slate/en/master/?ruby#system-setup-(ios)
 * </li>
 * <li>
 * The app InternationalMountains.app to be tested should be placed in the 
 * Current Working directory(src/test/resources).</li>
 * </ul>
 */
@MobileTest(appPath = "src/test/resources/apps/InternationalMountains.app", device = "iphone:8.1", deviceType = "iPhone Simulator")
@Test
public void testWithNativeApp() throws InterruptedException {
    //Log a screenshot to the report and label it "My Screenshot 1"
    SeLionReporter.log("My Screenshot 1", true);
    //To gain access to the IOSRemoteWebDriver, we use the thread safe helper method Grid.driver() which provides
    //an instance of IOSRemoteWebDriver for the current Test method. 
    List<WebElement> cells = Grid.driver().findElements(By.className("UIATableCell"));
    assertEquals(9, cells.size());
    // get the 1st mountain
    WebElement first = cells.get(0);
    first.click();
    Thread.sleep(10 * 1000);
    //Log a screenshot to the report and label it "My Screenshot 2"
    SeLionReporter.log("My Screenshot 2", true);
    // access the content
    By selector = By.xpath("//UIAStaticText[contains(@name,'climbed')]");
    WebElement text = Grid.driver().findElement(selector);
    Reporter.log(text.getAttribute("name"), true);
}

From source file:com.mycompany.myselion.sample.selion.AppiumSauceCloudTest.java

License:Apache License

/**
 * This test demonstrates how to use SeLion for running tests against a Native ANDROID app in sauce cloud.
 * This selendroid-test-app-0.15.0.apk must be uploaded to sauce temporary storage before running this test case.
 *//*from  w w w .  j a  v a 2 s. com*/
@Test
@MobileTest(appPath = "sauce-storage:selendroid-test-app-0.15.0.apk", device = "android:4.3", deviceType = "Android Emulator", additionalCapabilities = {
        "appiumVersion:1.4.13" })
public void testWithNativeAndroidApp() throws Exception {
    RemoteWebDriver driver = Grid.driver();
    WebDriverWaitUtils.waitUntilElementIsVisible("io.selendroid.testapp:id/my_text_field");
    WebElement textField = driver.findElement(By.id("io.selendroid.testapp:id/my_text_field"));
    assertEquals("true", textField.getAttribute("enabled"));
    textField.sendKeys("Appium Android Native Test");
    assertEquals("Appium Android Native Test", textField.getText());

}

From source file:com.mycompany.myselion.sample.selion.IOSNativeAppDemoTest.java

License:Apache License

/**
 * This test demonstrates how to use SeLion for running tests against a Native IOS app using appium.
 * This test case needs an local IOS simulator spawned. 
 *//*  w w  w. j av  a  2 s  .c  om*/
@MobileTest(appName = "InternationalMountains")
@Test
public void testMethod() throws InterruptedException {
    //Log a screenshot to the report and label it "My Screenshot 1"
    SeLionReporter.log("My Screenshot 1", true);
    //To gain access to the IOSRemoteWebDriver, we use the thread safe helper method Grid.driver() 
    //which provides an instance of IOSRemoteWebDriver for the current Test method. 
    List<WebElement> cells = Grid.driver().findElements(By.className("UIATableCell"));
    assertEquals(9, cells.size());

    // get the 1st mountain
    WebElement first = cells.get(0);
    first.click();
    Thread.sleep(10 * 1000);

    //Log a screenshot to the report and label it "My Screenshot 2"
    SeLionReporter.log("My Screenshot 2", true);

    // access the content
    By selector = By.xpath("//UIAStaticText[contains(@name,'climbed')]");
    WebElement text = Grid.driver().findElement(selector);
    Reporter.log(text.getAttribute("name"), true);
}

From source file:com.mycompany.myselion.sample.selion.SelendroidDemoTest.java

License:Apache License

/**
 * This test demonstrates how to use SeLion for running tests against ANDROID native app using selendroid.
 *//*from w ww.  j av  a 2  s . c  om*/
@Test
@MobileTest(appName = "io.selendroid.testapp:0.15.0", device = "android:19")
public void testNative() {
    RemoteWebDriver driver = Grid.driver();
    WebDriverWaitUtils.waitUntilElementIsVisible("//EditText[@id='my_text_field']");
    WebElement inputField = driver.findElement(By.xpath("//EditText[@id='my_text_field']"));
    assertEquals(inputField.getAttribute("enabled"), "true");
    inputField.sendKeys("Selendroid");
    assertEquals(inputField.getText(), "Selendroid");
}

From source file:com.nabla.project.fronter.selenium.tests.helper.SeleniumHelper.java

License:Open Source License

public static void testElementAttribute(final String id, String expectedResult, final WebDriver driver) {
    final WebElement message = driver.findElement(By.id(id));
    if (null == expectedResult) {
        expectedResult = "justify";
    }//from  www . j av  a  2  s .co m
    Assert.assertEquals(expectedResult, message.getAttribute("align"));
}

From source file:com.nexenta.qa.bs.wz.Test1Reg.java

@Test
public void registerMe() {
    WebElement msig = driver.findElement(By.id(reg.MachineSigById));
    String machinesig = msig.getAttribute("value");
    //String machinesig = driver.findElement(By.id(reg.MachineSigById)).get);
    logger.info("MSIG: " + machinesig);

    try {/*  w  w  w  .  ja v  a  2 s.c  om*/

        Process p = Runtime.getRuntime().exec(
                "/usr/bin/perl /home/user/selenium/utils/nxt-key/gen-com-key.pl " + machinesig + " TRIA 99");
        String line;
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        line = in.readLine();
        logger.info("LICENCE: " + line);
        WebElement lic = driver.findElement(By.id(reg.LicenseFieldByID));
        lic.clear();
        lic.sendKeys(line);
        in.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    driver.findElement(By.id(reg.RegisterOK)).click();
    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    assertEquals(driver.getTitle(), "Nexenta Management View: Appliance and Group Status");

}

From source file:com.nexenta.qa.bs.wz.Test3Registration.java

@Test
public void registerMe() {
    WebElement msig = driver.findElement(By.id(reg.MachineSigById));
    String machinesig = msig.getAttribute("value");
    //String machinesig = driver.findElement(By.id(reg.MachineSigById)).get);
    logger.info("MSIG: " + machinesig);

    try {// w ww .  j ava 2 s  .  c  o m

        Process p = Runtime.getRuntime().exec(
                "perl C:\\Users\\user\\Documents\\perl\\nxt-key\\gen-com-key.pl " + machinesig + " TRIA 99");
        String line;
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        line = in.readLine();
        logger.info("LICENCE: " + line);
        WebElement lic = driver.findElement(By.id(reg.LicenseFieldByID));
        lic.clear();
        lic.sendKeys(line);
        in.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    driver.findElement(By.id(reg.RegisterOK)).click();
    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    assertEquals(driver.getTitle(), "Nexenta Management View: Appliance and Group Status");

}

From source file:com.opera.core.systems.FindElementsTest.java

License:Apache License

@Test
public void testLinkText() {
    WebElement el = driver.findElementByLinkText("accumsan ante");
    assertEquals(el.getAttribute("id"), "local");
}

From source file:com.opera.core.systems.FindElementsTest.java

License:Apache License

@Test
public void testPartialLinkText() {
    WebElement el = driver.findElementByPartialLinkText("pell");
    assertEquals(el.getAttribute("id"), "external");
}