Selenium ndow().maximize(); //LEANFT:附加到浏览器 browser=BrowserFactory.attach(新BrowserDescription.Builder() .type(BrowserType.CHROME).openTit

Selenium ndow().maximize(); //LEANFT:附加到浏览器 browser=BrowserFactory.attach(新BrowserDescription.Builder() .type(BrowserType.CHROME).openTit,selenium,architecture,frameworks,leanft,Selenium,Architecture,Frameworks,Leanft,ndow().maximize(); //LEANFT:附加到浏览器 browser=BrowserFactory.attach(新BrowserDescription.Builder() .type(BrowserType.CHROME).openTitle(“优势购物”) .build()); //LEANFT:点击平板电脑按钮 browser.descripe(WebElement.class,新的WebElementDescription.Builder()) .className(“c

ndow().maximize(); //LEANFT:附加到浏览器 browser=BrowserFactory.attach(新BrowserDescription.Builder() .type(BrowserType.CHROME).openTitle(“优势购物”) .build()); //LEANFT:点击平板电脑按钮 browser.descripe(WebElement.class,新的WebElementDescription.Builder()) .className(“categoryCell”).tagName(“DIV”).innerText(“平板电脑商店现在”).build()).click(); //SELENIUM:在看到显示部分后展开它 (新WebDriverWait(chromeDriver,10)) .直到(新的预期条件){ @凌驾 public org.openqa.selenium.WebElement apply(org.openqa.selenium.WebDriver d){ 返回d.findElement(由.cssSelector(“h4#accordionAttrib0”); }})。单击(); //LEANFT:选择首选显示尺寸,单击首选平板电脑,然后将平板电脑添加到购物车中 browser.description(CheckBox.class,新的CheckBoxDescription.Builder() .type(“复选框”).role(“”).accessibilityName(“”).tagName(“输入”).name(“”).index(1.build()).set(true); browser.description(Image.class,new ImageDescription.Builder() .alt(“”).type(com.hp.lft.sdk.web.ImageType.NORMAL).tagName(“IMG”).index(1.build()).click(); browser.description(Button.class,new ButtonDescription.Builder() .buttonType(“提交”).tagName(“按钮”).name(“添加到购物车”).build()).click(); //硒:去购物车 chromeDriver.get(“http://156.152.164.67:8080/#/shoppingCart"); //LEANFT:结帐 browser.description(Button.class,new ButtonDescription.Builder() .buttonType(“提交”).tagName(“按钮”).name(“签出($1009.00)”).build()).click(); //SELENIUM:在看到按钮后注册为新用户 (新WebDriverWait(chromeDriver,10)) .直到(新的预期条件){ @凌驾 public org.openqa.selenium.WebElement apply(org.openqa.selenium.WebDriver d){ 返回d.findElement(By.xpath(“//DIV[@id=\'newClient\'”]/DIV[1]/SEC-FORM[1]/SEC-SENDER[1]/BUTTON[@role=\'BUTTON\'][1]”); }})。单击(); //LEANFT:填写用户名和电子邮件 字符串username=“U”+Calendar.getInstance().getTimeInMillis();//每次都是唯一的名称 browser.descripe(EditField.class,新的EditFieldDescription.Builder() .type(“文本”).tagName(“输入”).name(“用户名”).build()).setValue(用户名); browser.descripe(EditField.class,新的EditFieldDescription.Builder() .type(“文本”).tagName(“输入”).name(“用户电子邮件”).build()).setValue(“myuser_email@emailsite.org"); //SELENIUM:设置密码和确认密码 chromeDriver.findelementbypath(//SEC-VIEW/DIV[normalize-space()=\“*Password\”]/INPUT[1]”); chromeDriver.findelementbypath(“//SEC-VIEW/DIV[normalize-space()=\”*确认密码\“]/INPUT[1]”); //LEANFT:选中“我同意”复选框并注册,然后单击“下一次发货详细信息”。 browser.description(CheckBox.class,新的CheckBoxDescription.Builder() .type(“复选框”).tagName(“输入”).name(“注册协议”).build()).set(真); browser.description(Button.class,new ButtonDescription.Builder() .buttonType(“按钮”).tagName(“按钮”).name(“寄存器”).build()).click(); browser.description(Button.class,new ButtonDescription.Builder() .buttonType(“提交”).tagName(“按钮”).name(“下一步”).build()).click(); //SELENIUM:确认用户名并通过 chromeDriver.findelementbypath(“//DIV[@id=\\“paymentMethod\”]/DIV/DIV/DIV/SEC-FORM/SEC-VIEW/DIV[normalize-space()=\“*SafePay username\”]/INPUT[1]”; chromeDriver.findelementbypath(“//DIV[@id=\\“paymentMethod\”]/DIV/DIV/DIV/DIV/SEC-FORM/SEC-VIEW/DIV[normalize-space()=\“*SafePay password\”]/INPUT[1]”。sendKeys(“密码1”); //LEANFT:单击“立即付款”并确认付款已完成 browser.description(Button.class,new ButtonDescription.Builder() .buttonType(“按钮”).role(“按钮”).accessibilityName(“按钮”).tagName(“按钮”).name(“立即付款”).index(0.build())。单击(); 核实( browser.descripe(WebElement.class,新的WebElementDescription.Builder()) .tagName(“SPAN”).innerText(“感谢您使用Advantage购买”).build() .exists()); } }
@BeforeClass
public static void beforeLFTClass() throws Exception {
    globalSetup(CoreFunctionality.class);
}

@AfterClass
public static void afterLFTClass() throws Exception {
    globalTearDown();
}

@Test
public void runLeanFtThread() {
    // put selenium code here
             // ...
             // begin leanft part of test
    Thread leanftThread = new Thread( new Runnable() {

        @Override
        public void run() {
            try {
                test();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
    leanftThread.start();
    try {
        leanftThread.join();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}


public void test() throws Exception {

    //Starting Browser
    Browser browser = BrowserFactory.attach(new BrowserDescription.Builder().title(driver.getTitle()).build());
    Assert.assertEquals(browser.getTitle(), driver.getTitle());
}
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HP.LFT.SDK;
using HP.LFT.SDK.Web;
using Search_Regression_Test;
using TestAutomationReporting;
using UnifiedFramework;
using System.Configuration;
using System.Diagnostics;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using Selenium = OpenQA.Selenium;
namespace Search_Regression_Test
{
    [TestClass]
    public class LeanFtTest : UnitTestClassBase<LeanFtTest>
    {        
        static IBrowser browser;        
        static IWebDriver chromeDriver;

        [ClassInitialize]
        public static void ClassInitialize(TestContext context)
        {

            GlobalSetup(context);                        
            ChromeOptions CO = new ChromeOptions();
            CO.AddExtension(@"C:\Program Files (x86)\HP\LeanFT\Installations\Chrome\Agent.crx");
            chromeDriver = new ChromeDriver(CO);
            chromeDriver.Manage().Window.Maximize();

            browser = BrowserFactory.Attach(new BrowserDescription
            {
                Type = BrowserType.Chrome
            });
package com.demo;

import static org.junit.Assert.*;

import java.io.File;
import java.util.Calendar;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.Keys;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.hpe.leanft.selenium.By;
import com.hp.lft.report.Reporter;
import com.hp.lft.report.Status;
import com.hp.lft.sdk.web.*;
import com.hp.lft.verifications.Verify;


public class SeleniumTest extends UnitTestClassBase {
    private ChromeDriver chromeDriver;
    private Browser browser;
    public SeleniumTest() {

        System.setProperty("webdriver.chrome.driver",this.getClass().getResource("/chromedriver.exe").getPath());

    }

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
        instance = new SeleniumTest();
        globalSetup(SeleniumTest.class);
    }

    @AfterClass
    public static void tearDownAfterClass() throws Exception {
        globalTearDown();
    }

    @Before
    public void setUp() throws Exception {
        // SELENIUM: Construct and launch the browser with LeanFT agent
        ChromeOptions options = new ChromeOptions();
        File paths = new File("C:\\Program Files (x86)\\HP\\LeanFT\\Installations\\Chrome\\Agent.crx");
        options.addExtensions(paths);

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);

        chromeDriver = new ChromeDriver(options);

    }

    @After
    public void tearDown() throws Exception {
        // LEANFT: close the browser opened by selenium
        browser.close();
    }

    @Test
    public void test() throws Exception {

        // SELENIUM: Go to the Advantage shopping website and maximize it
        chromeDriver.get("http://156.152.164.67:8080/#/");
        chromeDriver.manage().window().maximize();

        // LEANFT: Attach to the browser
        browser = BrowserFactory.attach(new BrowserDescription.Builder()
                .type(BrowserType.CHROME).openTitle(" Advantage Shopping")
                .build());


        // LEANFT: Click on tablets button
        browser.describe(WebElement.class, new WebElementDescription.Builder()
                .className("categoryCell").tagName("DIV").innerText("TABLETS Shop Now ").build()).click();

        // SELENIUM: Expand the display section after it was seen
        (new WebDriverWait(chromeDriver, 10))
          .until(new ExpectedCondition<org.openqa.selenium.WebElement>(){
            @Override
            public org.openqa.selenium.WebElement apply(org.openqa.selenium.WebDriver d) {
                return d.findElement(By.cssSelector("h4#accordionAttrib0"));
            }}).click();


        // LEANFT: select the preferred display size, click the preferred tablet and add the tablet to the cart
        browser.describe(CheckBox.class, new CheckBoxDescription.Builder()
                .type("checkbox").role("").accessibilityName("").tagName("INPUT").name("").index(1).build()).set(true);

        browser.describe(Image.class, new ImageDescription.Builder()
                .alt("").type(com.hp.lft.sdk.web.ImageType.NORMAL).tagName("IMG").index(1).build()).click();

        browser.describe(Button.class, new ButtonDescription.Builder()
                .buttonType("submit").tagName("BUTTON").name("ADD TO CART").build()).click();

        // SELENIUM: go to cart
        chromeDriver.get("http://156.152.164.67:8080/#/shoppingCart");

        // LEANFT: checkout
        browser.describe(Button.class, new ButtonDescription.Builder()
                .buttonType("submit").tagName("BUTTON").name("CHECKOUT ($1,009.00)").build()).click();

        // SELENIUM: Register as a new user after the button was seen
        (new WebDriverWait(chromeDriver, 10))
          .until(new ExpectedCondition<org.openqa.selenium.WebElement>(){
            @Override
            public org.openqa.selenium.WebElement apply(org.openqa.selenium.WebDriver d) {
                return d.findElement(By.xpath("//DIV[@id=\"newClient\"]/DIV[1]/SEC-FORM[1]/SEC-SENDER[1]/BUTTON[@role=\"button\"][1]"));
            }}).click();


        // LEANFT: fill in the user name and email
        String username = "U" + Calendar.getInstance().getTimeInMillis(); // unique name each time
        browser.describe(EditField.class, new EditFieldDescription.Builder()
                .type("text").tagName("INPUT").name("userName").build()).setValue(username); 

        browser.describe(EditField.class, new EditFieldDescription.Builder()
                .type("text").tagName("INPUT").name("userEmail").build()).setValue("myuser_email@emailsite.org");

        // SELENIUM: Set password and confirm password
        chromeDriver.findElementByXPath("//SEC-VIEW/DIV[normalize-space()=\"*Password\"]/INPUT[1]").sendKeys("Password1");
        chromeDriver.findElementByXPath("//SEC-VIEW/DIV[normalize-space()=\"*Confirm password\"]/INPUT[1]").sendKeys("Password1");

        // LEANFT: check the 'I agree' checkbox and register, then click on next shipping details.
        browser.describe(CheckBox.class, new CheckBoxDescription.Builder()
                .type("checkbox").tagName("INPUT").name("registrationAgreement").build()).set(true);

        browser.describe(Button.class, new ButtonDescription.Builder()
                .buttonType("button").tagName("BUTTON").name("REGISTER").build()).click();

        browser.describe(Button.class, new ButtonDescription.Builder()
                .buttonType("submit").tagName("BUTTON").name("NEXT").build()).click();

        // SELENIUM: confirm the user name and pass
        chromeDriver.findElementByXPath("//DIV[@id=\"paymentMethod\"]/DIV/DIV/SEC-FORM/SEC-VIEW/DIV[normalize-space()=\"*SafePay username\"]/INPUT[1]").sendKeys(username);
        chromeDriver.findElementByXPath("//DIV[@id=\"paymentMethod\"]/DIV/DIV/SEC-FORM/SEC-VIEW/DIV[normalize-space()=\"*SafePay password\"]/INPUT[1]").sendKeys("Password1");

        // LEANFT: click "Pay now" and confirm payment was done
        browser.describe(Button.class, new ButtonDescription.Builder()
                .buttonType("button").role("button").accessibilityName("").tagName("BUTTON").name("PAY NOW").index(0).build()).click();
        Verify.isTrue(
                browser.describe(WebElement.class, new WebElementDescription.Builder()
                        .tagName("SPAN").innerText("Thank you for buying with Advantage").build())
                            .exists());
    }
}