Skip to content

Commit

Permalink
XCTest Demo with Xcode 9
Browse files Browse the repository at this point in the history
  • Loading branch information
Shashikant86 committed Jun 10, 2017
1 parent fc7cd98 commit fdf2b64
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 18 deletions.
101 changes: 101 additions & 0 deletions Xcode9-XCTest.xcodeproj/xcshareddata/xcschemes/Xcode9-XCTest.xcscheme
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9B5674D01EEC0A7A00795558"
BuildableName = "Xcode9-XCTest.app"
BlueprintName = "Xcode9-XCTest"
ReferencedContainer = "container:Xcode9-XCTest.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9B5674E41EEC0A7B00795558"
BuildableName = "Xcode9-XCTestUITests.xctest"
BlueprintName = "Xcode9-XCTestUITests"
ReferencedContainer = "container:Xcode9-XCTest.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9B5674D01EEC0A7A00795558"
BuildableName = "Xcode9-XCTest.app"
BlueprintName = "Xcode9-XCTest"
ReferencedContainer = "container:Xcode9-XCTest.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9B5674D01EEC0A7A00795558"
BuildableName = "Xcode9-XCTest.app"
BlueprintName = "Xcode9-XCTest"
ReferencedContainer = "container:Xcode9-XCTest.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9B5674D01EEC0A7A00795558"
BuildableName = "Xcode9-XCTest.app"
BlueprintName = "Xcode9-XCTest"
ReferencedContainer = "container:Xcode9-XCTest.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>
Expand Up @@ -4,11 +4,24 @@
<dict>
<key>SchemeUserState</key>
<dict>
<key>Xcode9-XCTest.xcscheme</key>
<key>Xcode9-XCTest.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>9B5674D01EEC0A7A00795558</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>9B5674E41EEC0A7B00795558</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
36 changes: 31 additions & 5 deletions Xcode9-XCTest/Base.lproj/Main.storyboard
@@ -1,26 +1,52 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.17" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.14"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Xcode9_XCTest" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VyY-A7-kYj">
<rect key="frame" x="46" y="256" width="292" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<accessibility key="accessibilityConfiguration" identifier="New"/>
<fontDescription key="fontDescription" type="system" pointSize="27"/>
<state key="normal" title="What's New in XCTest? "/>
<connections>
<action selector="whatNewButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="nH7-EI-qcK"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Discover What's New" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="LUQ-Ul-LRE">
<rect key="frame" x="57" y="343" width="272" height="49"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.69715948065288491" green="0.68053193281906565" blue="0.75131557642487046" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<connections>
<outlet property="xctestLabel" destination="LUQ-Ul-LRE" id="uP7-AL-kQd"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="136.80000000000001" y="138.98050974512745"/>
</scene>
</scenes>
</document>
5 changes: 5 additions & 0 deletions Xcode9-XCTest/ViewController.swift
Expand Up @@ -10,6 +10,11 @@ import UIKit

class ViewController: UIViewController {

@IBOutlet weak var xctestLabel: UILabel!
@IBAction func whatNewButton(_ sender: Any) {
xctestLabel.text = "There is a lot"

}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Expand Down
62 changes: 50 additions & 12 deletions Xcode9-XCTestUITests/Xcode9_XCTestUITests.swift
Expand Up @@ -12,25 +12,63 @@ class Xcode9_XCTestUITests: XCTestCase {

override func setUp() {
super.setUp()

// Put setup code here. This method is called before the invocation of each test method in the class.

// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
XCUIApplication().launch()

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.

super.tearDown()
}

func testExample() {
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
func waiterResultWithExpextation(_ element: XCUIElement) -> XCTWaiter.Result {
let myPredicate = NSPredicate(format: "exists == true")
let myExpectation = expectation(for: myPredicate, evaluatedWith: element,
handler: nil)

let result = XCTWaiter().wait(for: [myExpectation], timeout: 5)
return result
}

func testXCUISiriService() {
XCUIApplication().launch()
XCUIDevice().siriService.activate(voiceRecognitionText: "Open News")
}

func testXCWaiterfeatures() {
let whatsNewButton = XCUIApplication().buttons["New"]
whatsNewButton.tap()
XCTAssertTrue(waiterResultWithExpextation(whatsNewButton) == .completed)
}

func testMultipleApps() {

let settingsApp = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
XCUIApplication().launch()
settingsApp.terminate()
print(settingsApp.state.rawValue)
}

func testActivitiesScreenShotsAttachments () {
XCTContext.runActivity(named: "Given I launch an Xcode9-XCTest app") { _ in
XCUIApplication().launch()
}

XCTContext.runActivity(named: "When I tap what is new button") { _ in
XCUIApplication().buttons["New"].tap()
}

XCTContext.runActivity(named: "Then I should see new features of XCTest") { _ in
let newXCTestFeatures = XCUIApplication().staticTexts["There is a lot"]
newXCTestFeatures.tap()
XCTAssertTrue(newXCTestFeatures.exists)
}

XCTContext.runActivity(named: "When I use attachment to screenshot") { (activity) in
let screen = XCUIScreen.main
let fullscreenshot = screen.screenshot()
let fullScreenshotAttachment = XCTAttachment(screenshot: fullscreenshot)
fullScreenshotAttachment.lifetime = .deleteOnSuccess
activity.add(fullScreenshotAttachment)
}
}
}

0 comments on commit fdf2b64

Please sign in to comment.