fitnesse/appium/selenium - schedschd.ws/hosted_files/aimhdc2016/64/hdcpresentation.pdf ·...

30
Fitnesse/Appium/Selenium Herb Scruggs – Lead Test Automation Engineer – Client Resources Inc

Upload: trinhkhanh

Post on 10-Jun-2018

236 views

Category:

Documents


3 download

TRANSCRIPT

Fitnesse/Appium/SeleniumHerb Scruggs – Lead Test Automation Engineer – Client Resources Inc

Automation

Why YOU should Automate Tests

• Manual Testing of all work flows, all fields, all negative scenarios is time and cost consuming

• Automation does not require Human intervention. You can run automated test unattended (overnight)

• Automation increases speed of test execution

• Automation helps increase Test Coverage

• Manual Testing can become boring and hence error prone.

• Free up time for exploratory testing for manual testers

Automation

Keywords• Selenium – software to test web browsers• Appium – software to test mobile apps/web• Fitnesse – software to test the api• API – business logic layer of the application• Jenkins – Continuous Integration Server• Maven – build automation tool.• TestNG – testing framework• TestRail – Test Repository• URI – Universal Resource Identifier

Automation

Types of Testing Covering• Graphical User Interface (GUI) testing – Selenium and Appium

• API driven Testing - Fitnesse

Fitnesse§ Born in 2001§ Written in Java§ The core is written in Java, but it allows fixtures to be created in many different languages.

What is it§ Fully integrated standalone wiki and acceptance testing framework§ In general, developers can write fixtures that allow non-coders to provide input/output against the

fixtures for results.§ CRI uses a RestFixture by SmartRics for testing Rest API§ https://github.com/smartrics/RestFixture

Why use Fitnesse for API?

6

Ø The REST Fixture is simple to useØ BA/QA can write the the tests with little dev helpØ Validate HTTP responses, Headers and BodyØ Uses a Wiki syntax so no need to know a programming languageØ Create Suites of Tests for different version of your API Tests

What does the RestFixutre look like?

7

• How to Start• nohup java -jar lib/fitnesse-standalone.jar -p 9091 &

• RestFixture is super easy to use:• |VERB|uri|?ret|?headers|?body|• VERB = GET/PUT/POST/DELETE• URI is the URI string of the request• The Next 3 (?) are what comes back from the API call, the http response

code, headers and body

Real World Example

8

Example Code|VERB|uri|?ret|?headers|?body|

|Table:smartrics.rest.fitnesse.fixture.RestFixture|http://jsonplaceholder.typicode.com/posts||GET| /1 | 200 | | |

Fitnesse Demo – Standalone with Testrails

9

How Does CRI Implement?

10

Fitnesse Demo – Jenkinswith Testrails

11

Appium§ Born in 2011§ Developer origins from Zoosk§ Name = Selenium for Apps§ Founder of Selenium played role in getting Appium open sourced§ http://appium.io/history.html?lang=en§ 1.0 – Stable release in 2014§ Currently 1.5§ Full developer support from Sauce Labs

What is it§ Open-source tool for automating native, mobile web, and hybrid applications on iOS and Android

platforms. § Built upon Node.js framework.§ "cross-platform": it allows you to write tests against multiple platforms (iOS, Android), using the same

API. Great for developing Smoke tests of web applications and regression suites

Languages§ Appium Client Libraries

JavaC#RubyPythonJavascript (Node)PHPhttp://appium.io/downloads.html

Selenium§ Born in 2004§ Developer origins from Thoughtworks/Google/Facebook§ http://www.seleniumhq.org/about/history.jsp§ 1.0 – Core, IDE, Remote Control (RC) - Thoughtworks§ 2.0 – Webdriver, Grid - Google§ 3.0 beta – Removed Remote Control interface – Google/Facebook

What is it§ Open Source Browser based Test Automation software§ Automate Browsers for testing, but not limited to§ Great for developing Smoke tests of web applications and regression suites§ Has support of the some of the largest browser vendors

Why use Selenium?

15

Ø Selenium has the capability to operate on almost every OS

Ø Open source testing tool and hence it serves for cost-effective automation testing

Ø Supports multiple languagesØ Supports a range of browserØ Very dynamic developer community

that is backed by GoogleØ Robust methods for location of

elements• ClassName• Id• Name• XPath• LinkText• Partial LinkText• CSS

Ø Convenient to implement frameworks that revolve around Object oriented programming like Keyword Driven, Data driven and Hybrid

Ø Integrates nicely with of open source frameworks like TestNG, JUnit, Nunit

Ø Execute simultaneous tests against different browsers

Ø Docker containers available for Firefox and Chrome

Browsers§ Most Common but not limited to

IEFirefoxChromeSafarihttp://www.seleniumhq.org/download/

Languages§ Supported but not limited to

JavaC#RubyPythonJavascript (Node)http://www.seleniumhq.org/download/

How Does CRI Implement?

17

Maven Pom Dependencies<dependencies>

<dependency><groupId>org.testng</groupId><artifactId>testng</artifactId><version>6.9.10</version>

</dependency><dependency>

<groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-java</artifactId><version>2.53.0</version>

</dependency><dependency>

<groupId>io.appium</groupId><artifactId>java-client</artifactId><version>4.1.2</version>

</dependency></dependencies>

Maven Pom TestNG<build>

<sourceDirectory>src/main/java</sourceDirectory><plugins>

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.19.1</version><configuration>

<suiteXmlFiles><suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>

</suiteXmlFiles></configuration>

</plugin></plugins>

</build>

TestNG

<parameter name="browse" value="ANDROID_APP"></parameter><parameter name="virtualDevice" value="ANDROID"></parameter><parameter name="platformName" value="ANDROID"></parameter><parameter name="platformVersion" value="21"></parameter><parameter name="apkfile" value="Downloads/FNBO-kansas-criCts.apk"></parameter><parameter name="appPackage" value="com.fnts.android.qa"></parameter><parameter name="appActivity" value="com.fnts.android.activity.SplashActivity"></parameter><parameter name="appWaitActivity" value="com.fnts.android.activity.LoginActivity"></parameter><parameter name="udid" value="491364af"></parameter> <parameter name="androidAppTestRun" value = "2399"></parameter><parameter name="testLogLevel" value = "info"></parameter><parameter name="appiumLogLevel" value="warn"></parameter>

TestNG

<test name = "Start Appium" preserve-order="true"><groups><run><include name='StartAppium'/></run></groups><classes><class name="com.cri.appium.AppiumServer"></class></classes>

</test><test name = "Test" preserve-order="true">

<groups><run><include name='smokeTests'/></run></groups><classes><class name="com.cri.tests.login.Login"></class> </classes>

</test><test name = "Stop Appium" preserve-order="true">

<groups><run><include name='StopAppium'/></run></groups><classes><class name="com.cri.appium.AppiumServer"></class></classes>

</test>

Programmatically Start Appiumpublic static void AppiumService(ITestContext context) {

DesiredCapabilities serverCapabilities = new DesiredCapabilities();serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,

context.getCurrentXmlTest().getParameter("platformName"));serverCapabilities.setCapability(MobileCapabilityType.FULL_RESET, false);serverCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60);

AppiumService = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().withCapabilities(serverCapabilities)

.withIPAddress("127.0.0.1")

.withArgument(GeneralServerFlag.SESSION_OVERRIDE)

.withArgument(GeneralServerFlag.LOG_LEVEL, context.getCurrentXmlTest().getParameter("appiumLogLevel")));

AppiumService.start();}

Page Factory Object@FindBy(how = How.XPATH, using = "//input[@aria-label='UserID']")@iOSFindBy(id = "loginTextField")public WebElement UserName;

@AndroidFindAll({@AndroidFindBy(uiAutomator = "new UiSelector().className(\"android.widget.EditText\")")

})public List<WebElement> UserNamePassword;

@FindBy(how = How.XPATH, using = "//input[@aria-label='Password']")@iOSFindBy(id = "passwordTextField")public WebElement PassWord;

@FindBy(how = How.XPATH, using = "//button[@aria-label='LoginButton']")@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"com.ccnew.android.qa:id/login_button\")")@iOSFindBy(id = "LoginCell")public WebElement LoginButton;

Example Login Using Page Factory ElementsLogin = new LoginPageObjects(driver);PageFactory.initElements(new AppiumFieldDecorator(driver), Login);public void login() throws Exception {

if (Utils.getBrowserType().contains("ANDROID")) {type(UserName, getUsername());type(PassWord, getPassword());driver.navigate().back();click(LoginButton);

} else {waitForVisibilityOfElement(ContactUs);type(UserName, getUsername());type(PassWord, getPassword());

}click(LoginButton);

}

@BeforeClass(alwaysRun = true)public void beforeClass(ITestContext context)

throws ClassNotFoundException {driver = Utils.getDriver(context);Login = new LoginPageObject(driver);//If MobilePageFactory.initElements(new

AppiumFieldDecorator(driver), Login);//If BrowserPageFactory.initElements(driver, Login);

}@Test(priority = 10, groups = {"smokeTests"})public void login(ITestContext context) throws

Exception {Login.login();

}

@Test(priority = 20, groups = {"smokeTests"})public void testTwo(ITestContext context)

throws Exception {Login.logout(context);

}@AfterMethod(alwaysRun = true)

public void afterMethod(ITestContext context, ITestResult result) {

//Do something after every test?}@AfterClass(alwaysRun = true)public void afterClass(ITestContext context) {

//This is where you close and tear down the driver}

Fitnesse + Appium + Selenium =

Questions

Thank You

Herb Scruggs – Lead Test Automation Engineer – Client Resources [email protected]