109 lines
4.0 KiB
Swift
109 lines
4.0 KiB
Swift
//
|
||
// XUITEST.swift
|
||
// XUITEST
|
||
//
|
||
// Created by Max Hunt on 18/05/2020.
|
||
// Copyright © 2020 smt. All rights reserved.
|
||
//
|
||
|
||
import XCTest
|
||
import SwiftyJSON
|
||
|
||
class XUITEST: XCTestCase {
|
||
|
||
override func setUpWithError() throws {
|
||
// 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
|
||
|
||
// 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 tearDownWithError() throws {
|
||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||
}
|
||
|
||
func testExample() throws {
|
||
// UI tests must launch the application that they test.
|
||
let app = XCUIApplication()
|
||
app.launch()
|
||
|
||
// Use recording to get started writing UI tests.
|
||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||
}
|
||
|
||
func testLogin(){
|
||
|
||
let app = XCUIApplication()
|
||
app/*@START_MENU_TOKEN@*/.staticTexts["Login"]/*[[".buttons[\"Login\"].staticTexts[\"Login\"]",".staticTexts[\"Login\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
|
||
app/*@START_MENU_TOKEN@*/.staticTexts["Log In"]/*[[".buttons[\"Log In\"].staticTexts[\"Log In\"]",".staticTexts[\"Log In\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()
|
||
|
||
|
||
let onSwitch = app.switches["onSwitch"]
|
||
let onSwitchEnabled = NSPredicate(format: "isEnabled == true")
|
||
|
||
expectation(for: onSwitchEnabled, evaluatedWith: onSwitch, handler: nil)
|
||
waitForExpectations(timeout: 2, handler: nil)
|
||
|
||
NSLog("HERE==================")
|
||
onSwitch.tap()
|
||
let expectedValue:Bool = (onSwitch.value != nil)
|
||
NSLog(String(expectedValue))
|
||
NSLog("HERE==================")
|
||
|
||
let parameters = ["":""] as [String : Any]
|
||
let url = URL(string: "http://localhost:5050/gst-debug")! //change the url
|
||
let session = URLSession.shared
|
||
var request = URLRequest(url: url)
|
||
request.httpMethod = "POST" //set http method as POST
|
||
|
||
do {
|
||
request.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted) // pass dictionary to nsdata object and set it as request body
|
||
} catch let error {
|
||
print(error.localizedDescription)
|
||
}
|
||
|
||
NSLog("22222==================")
|
||
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
||
request.addValue("application/json", forHTTPHeaderField: "Accept")
|
||
|
||
|
||
|
||
//create dataTask using the session object to send data to the server
|
||
let task = session.dataTask(with: request as URLRequest, completionHandler: { data, response, error in
|
||
NSLog("33333==================")
|
||
guard error == nil else {
|
||
return
|
||
}
|
||
guard let data = data else {
|
||
return
|
||
}
|
||
do {
|
||
let responseJSON = try? JSON(data: data)
|
||
let status = responseJSON?["state"].stringValue
|
||
var bStatus = false
|
||
if status == "true" {
|
||
bStatus = true
|
||
}
|
||
NSLog("@@@@Checking updated db@@@@@")
|
||
XCTAssert(expectedValue == bStatus)
|
||
XCTAssert(false)
|
||
}
|
||
})
|
||
let succApi = NSPredicate(value: <#T##Bool#>)
|
||
task.resume()
|
||
|
||
|
||
}
|
||
|
||
func testLaunchPerformance() throws {
|
||
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, *) {
|
||
// This measures how long it takes to launch your application.
|
||
// measure(metrics: [XCTOSSignpostMetric.applicationLaunch]) {
|
||
// XCUIApplication().launch()
|
||
// }
|
||
}
|
||
}
|
||
}
|