在测试套件中运行测试用例文件后,如何避免浏览器关闭?

时间:2019-01-28 05:54:04

标签: python automation cucumber bdd squish

我正在使用Squish工具自动化Web应用程序。在套件中,我有两个测试用例文件。 但是当我将其作为套件运行时,浏览器将关闭并重新启动以用于下一个测试用例。

public class MyFirebaseMessagingService extends FirebaseMessagingService {

private static final String TAG = "MyFirebaseMsgService";

/**
 * Called when message is received.
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    try {
        // [START_EXCLUDE]
        // There are two types of messages data messages and notification messages. Data messages are handled
        // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
        // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
        // is in the foreground. When the app is in the background an automatically generated notification is displayed.
        // When the user taps on the notification they are returned to the app. Messages containing both notification
        // and data payloads are treated as notification messages. The Firebase console always sends notification
        // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
        // [END_EXCLUDE]

        // TODO(developer): Handle FCM messages here.
        Map<String, String> data = remoteMessage.getData();
        String value1 = data.get("key_1");
        String value2 = data.get("key_2");
        String title=data.get("title");
        String msg=data.get("body");
        Log.d("Backgraound", value1);
        Log.d(TAG, "From: " + remoteMessage.getFrom());

        // Check if message contains a data payload.
        if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data payload: " + remoteMessage.getData());

        }

        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
        }

        // Also if you intend on generating your own notifications as a result of a received FCM
        // message, here is where that should be initiated. See sendNotification method below.
        sendNotification(title,msg,value1,value2);
    }catch (Exception e){
        Log.d("Error Line Number",Log.getStackTraceString(e));
    }
}

private void sendNotification(String title,String messageBody, String val1,String val2) {
    try {
        Intent intent = new Intent(this, Notification_activity.class);
        //Bundle bundle = getApplicationContext().getExtras();
        Bundle basket = new Bundle();
        basket.putString("key_1", val1);
        basket.putString("key_2", val2);
        intent.putExtras(basket);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);

        String channelId = getString(R.string.default_notification_channel_id);
        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)
                        .setSmallIcon(R.drawable.spacebar_round)
                        .setContentTitle(title)
                        .setContentText(messageBody)
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(pendingIntent)
                        .setColor( getResources().getColor(R.color.colorPrimary))
                        .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(),
                                R.mipmap.ic_launcher));

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // Since android Oreo notification channel is needed.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(channelId,
                    "Channel human readable title",
                    NotificationManager.IMPORTANCE_DEFAULT);
            notificationManager.createNotificationChannel(channel);
        }

        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
    }catch (Exception e){
        Log.d("Error Line Number",Log.getStackTraceString(e));
    }
}
}

此方法调用发生在属于第一个测试用例文件的语句中。因此,为了不重新启动应用程序,我必须做些什么更改。

1 个答案:

答案 0 :(得分:1)

Squish始终会在测试用例结束时关闭AUT(被测应用程序)或在该测试用例中启动的浏览器(如果AUT /浏览器仍在运行)。

要通过Squish for Web避免这种情况,您必须连接到运行的浏览器,这在Attaching to a running Web Browser中进行了说明。

由于设置步骤不同,并且每个浏览器的设置时间都较长(并且可能会更改),因此我不会在此处复制该信息(可能会降低投票权或不接受此信息作为适当的独立答案)

然后,将浏览器配置为可连接并运行后,就可以使用attachToBrowser()函数将其连接到该浏览器。

PS:您将必须考虑如何处理上一个测试用例因错误而中止,使浏览器处于“未知”状态而不是下一个测试用例的预期状态的情况。